From patchwork Fri Nov 29 13:08:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1202474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514858-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Xd89MSUb"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="CKooA1L/"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47PZbl6YfGz9sPZ for ; Sat, 30 Nov 2019 00:09:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=wKWNlIegjhhgYDS6xd+weCJn++Y8p8HrYv3BSDYf1UOvrQDr+b 3EEDPTISV1g/z2+CWdXdLWRhYma/cEKIPcoSKx4rjSfXT/MSu2PKlCPfV2ew6Kew J3WZ7vAnSdPChVb6uxm8Gz0CGCMwka6V1b/KxYRMH9hEfUiviPRLW9EsE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=gG69GPb/H3VsCAVFOMgsvbvLyFY=; b=Xd89MSUbXKt2cIzltTRV yVhUuJTziIHiXmcoIVmumF4+Av4HZnVL1S8BSazs7ufjQBs63I5b5ciDrX7rO/XH i2bTpqUO1mCsmtBTOuL+TUncHirntntG1S/JjTXzLLhYxFR47nKSpPVn/uM6wuAS VKXbnlPaHCzkTsOOVraTWFM= Received: (qmail 51353 invoked by alias); 29 Nov 2019 13:09:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 51337 invoked by uid 89); 29 Nov 2019 13:09:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=lately, ag, 278834, sk:cp_expr X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 29 Nov 2019 13:09:28 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xATD4K15139871; Fri, 29 Nov 2019 13:09:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2019-08-05; bh=rHvSYCMAkRt0gpc7X/cDOHDFLHbI6xpRrks3wxFKtPo=; b=CKooA1L/AZ+Gt+utCZFXz7hn1moY/FjSP1SghlTSnnyqDUk36azbTcttTzedktzH7hjy StaWRmZFa9oAKV0d7PL2FWN9oSPop/ZPCqR7yZSSHMda7tGMylMweGVsuEYihXaUPVKa gjqmAeVu4hVWBitfa136+0DnRkjQFaMrEsUbTMyaxS1d0RPrM+USBbrqWxa1tEU7CqhS HUqGDHmUQO3bxZdGiZGxJXgkJ91Juyn1eeN5kF9JqG9FbywLEP7fniAa8DKLx4aX/TtH JnrhopgejFTLGx/m0Fcnnjd8A3rrWV+kyWA7IDLiYqVh+2asYb+f0lh7QiWEW7btuGsE 1g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2wev6uu7nm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Nov 2019 13:09:26 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xATD9LhP124656; Fri, 29 Nov 2019 13:09:25 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2wjh12mmd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Nov 2019 13:09:20 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xATD8pDV023391; Fri, 29 Nov 2019 13:08:51 GMT Received: from [192.168.1.4] (/79.26.212.60) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Nov 2019 05:08:50 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] A few more cp_expr_loc_or_input_loc and a diagnostic regression fix Message-ID: <4d09ce98-58b8-1506-0dc5-2f7ff20241b1@oracle.com> Date: Fri, 29 Nov 2019 14:08:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, a few more rather straightforward uses for cp_expr_loc_or_input_loc. Additionally, while working on the latter, I noticed that, compared to say, gcc-7, lately the code we have in cp_build_addr_expr_1 to diagnose taking the address of 'main' often doesn't work anymore, when the argument is wrapped in a location_wrapper. The below fixes that by using tree_strip_any_location_wrapper in the DECL_MAIN_P check, which works fine, but I can imagine various other ways to solve the issue... Tested x86_64-linux. Thanks, Paolo. ////////////////////// /cp 2019-11-29 Paolo Carlini * typeck.c (cp_build_addr_expr_1): Use cp_expr_loc_or_input_loc in a few additional places. (check_return_expr): Likewise. * typeck.c (cp_build_addr_expr_1): Use tree_strip_any_location_wrapper for address of main pedwarn. /testsuite 2019-11-29 Paolo Carlini * g++.dg/diagnostic/inconsistent-deduction-1.C: New. * g++.dg/diagnostic/returning-a-value-1.C: Likewise. * g++.dg/cpp0x/decltype3.C: Check location(s) too. * g++.dg/cpp0x/decltype4.C: Likewise. * g++.dg/cpp0x/lambda/lambda-deduce-ext-neg.C: Likewise. * g++.dg/cpp2a/consteval13.C: Likewise. * g++.dg/expr/pmf-1.C: Likewise. * g++.dg/other/ptrmem2.C: Likewise. * g++.dg/template/ptrmem17.C: Likewise. * g++.old-deja/g++.bugs/900213_03.C: Likewise. * g++.old-deja/g++.other/pmf7.C: Likewise. * g++.old-deja/g++.other/ptrmem7.C: Likewise. * g++.dg/diagnostic/main2.C: New. Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 278834) +++ cp/typeck.c (working copy) @@ -6103,12 +6103,14 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue else if (current_class_type && TREE_OPERAND (arg, 0) == current_class_ref) /* An expression like &memfn. */ - permerror (input_location, "ISO C++ forbids taking the address of an unqualified" + permerror (cp_expr_loc_or_input_loc (arg), + "ISO C++ forbids taking the address of an unqualified" " or parenthesized non-static member function to form" " a pointer to member function. Say %<&%T::%D%>", base, name); else - permerror (input_location, "ISO C++ forbids taking the address of a bound member" + permerror (cp_expr_loc_or_input_loc (arg), + "ISO C++ forbids taking the address of a bound member" " function to form a pointer to member function." " Say %<&%T::%D%>", base, name); @@ -6154,13 +6156,13 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue arg = build1 (CONVERT_EXPR, type, arg); return arg; } - else if (pedantic && DECL_MAIN_P (arg)) + else if (pedantic && DECL_MAIN_P (tree_strip_any_location_wrapper (arg))) { /* ARM $3.4 */ /* Apparently a lot of autoconf scripts for C++ packages do this, so only complain if -Wpedantic. */ if (complain & (flag_pedantic_errors ? tf_error : tf_warning)) - pedwarn (input_location, OPT_Wpedantic, + pedwarn (cp_expr_loc_or_input_loc (arg), OPT_Wpedantic, "ISO C++ forbids taking address of function %<::main%>"); else if (flag_pedantic_errors) return error_mark_node; @@ -6218,7 +6220,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue if (TYPE_REF_P (TREE_TYPE (t))) { if (complain & tf_error) - error ("cannot create pointer to reference member %qD", t); + error_at (cp_expr_loc_or_input_loc (arg), + "cannot create pointer to reference member %qD", t); return error_mark_node; } @@ -6254,8 +6257,9 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue || !DECL_IMMEDIATE_FUNCTION_P (current_function_decl))) { if (complain & tf_error) - error ("taking address of an immediate function %qD", - stripped_arg); + error_at (cp_expr_loc_or_input_loc (arg), + "taking address of an immediate function %qD", + stripped_arg); return error_mark_node; } if (TREE_CODE (stripped_arg) == FUNCTION_DECL @@ -9689,7 +9693,8 @@ check_return_expr (tree retval, bool *no_warning) if (DECL_DESTRUCTOR_P (current_function_decl)) { if (retval) - error ("returning a value from a destructor"); + error_at (cp_expr_loc_or_input_loc (retval), + "returning a value from a destructor"); return NULL_TREE; } else if (DECL_CONSTRUCTOR_P (current_function_decl)) @@ -9700,7 +9705,8 @@ check_return_expr (tree retval, bool *no_warning) error ("cannot return from a handler of a function-try-block of a constructor"); else if (retval) /* You can't return a value from a constructor. */ - error ("returning a value from a constructor"); + error_at (cp_expr_loc_or_input_loc (retval), + "returning a value from a constructor"); return NULL_TREE; } @@ -9762,11 +9768,13 @@ check_return_expr (tree retval, bool *no_warning) else if (!same_type_p (type, functype)) { if (LAMBDA_FUNCTION_P (current_function_decl)) - error ("inconsistent types %qT and %qT deduced for " - "lambda return type", functype, type); + error_at (cp_expr_loc_or_input_loc (retval), + "inconsistent types %qT and %qT deduced for " + "lambda return type", functype, type); else - error ("inconsistent deduction for auto return type: " - "%qT and then %qT", functype, type); + error_at (cp_expr_loc_or_input_loc (retval), + "inconsistent deduction for auto return type: " + "%qT and then %qT", functype, type); } functype = type; } @@ -9800,7 +9808,7 @@ check_return_expr (tree retval, bool *no_warning) its side-effects. */ finish_expr_stmt (retval); else if (retval != error_mark_node) - permerror (input_location, + permerror (cp_expr_loc_or_input_loc (retval), "return-statement with a value, in function " "returning %qT", valtype); current_function_returns_null = 1; Index: testsuite/g++.dg/cpp0x/decltype3.C =================================================================== --- testsuite/g++.dg/cpp0x/decltype3.C (revision 278834) +++ testsuite/g++.dg/cpp0x/decltype3.C (working copy) @@ -54,7 +54,7 @@ class B { }; CHECK_DECLTYPE(decltype(aa.*&A::a), int&); -decltype(aa.*&A::b) zz; // { dg-error "cannot create pointer to reference member" "cannot" } +decltype(aa.*&A::b) zz; // { dg-error "18:cannot create pointer to reference member" "cannot" } CHECK_DECLTYPE(decltype(caa.*&A::a), const int&); Index: testsuite/g++.dg/cpp0x/decltype4.C =================================================================== --- testsuite/g++.dg/cpp0x/decltype4.C (revision 278834) +++ testsuite/g++.dg/cpp0x/decltype4.C (working copy) @@ -23,7 +23,7 @@ struct A { }; CHECK_DECLTYPE(decltype(&A::x), int A::*); -decltype(&A::y) Ay; // { dg-error "cannot create pointer to reference member|invalid type" } +decltype(&A::y) Ay; // { dg-error "14:cannot create pointer to reference member|invalid type" } CHECK_DECLTYPE(decltype(&A::foo), int (A::*) (char)); CHECK_DECLTYPE(decltype(&A::bar), int& (A::*) () const); Index: testsuite/g++.dg/cpp0x/lambda/lambda-deduce-ext-neg.C =================================================================== --- testsuite/g++.dg/cpp0x/lambda/lambda-deduce-ext-neg.C (revision 278834) +++ testsuite/g++.dg/cpp0x/lambda/lambda-deduce-ext-neg.C (working copy) @@ -11,7 +11,7 @@ template int f (T t) { if (b) return t.fn1(); else - return t.fn2(); // { dg-error "inconsistent types" } + return t.fn2(); // { dg-error "19:inconsistent types" } }(t); } Index: testsuite/g++.dg/cpp2a/consteval13.C =================================================================== --- testsuite/g++.dg/cpp2a/consteval13.C (revision 278834) +++ testsuite/g++.dg/cpp2a/consteval13.C (working copy) @@ -10,8 +10,8 @@ void foo () { auto qux = [] (fnptr a = quux ()) consteval { return a (); }; - constexpr auto c = qux (baz); // { dg-error "taking address of an immediate function" } - constexpr auto d = qux (bar); // { dg-error "taking address of an immediate function" } + constexpr auto c = qux (baz); // { dg-error "28:taking address of an immediate function" } + constexpr auto d = qux (bar); // { dg-error "28:taking address of an immediate function" } static_assert (c == 1); static_assert (d == 42); } Index: testsuite/g++.dg/diagnostic/inconsistent-deduction-1.C =================================================================== --- testsuite/g++.dg/diagnostic/inconsistent-deduction-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/inconsistent-deduction-1.C (working copy) @@ -0,0 +1,9 @@ +// { dg-do compile { target c++14 } } + +void foo(); +auto bar(bool b) +{ + if (b) + return 0; + return foo(); // { dg-error "13:inconsistent deduction for auto return type: .int. and then .void." } +} Index: testsuite/g++.dg/diagnostic/main2.C =================================================================== --- testsuite/g++.dg/diagnostic/main2.C (nonexistent) +++ testsuite/g++.dg/diagnostic/main2.C (working copy) @@ -0,0 +1,8 @@ +int main (); + +void foo (int (*) ()); + +void bar () +{ + foo (main); // { dg-error "8:ISO C\\+\\+ forbids taking address of function" } +} Index: testsuite/g++.dg/diagnostic/returning-a-value-1.C =================================================================== --- testsuite/g++.dg/diagnostic/returning-a-value-1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/returning-a-value-1.C (working copy) @@ -0,0 +1,8 @@ +int foo(); + +struct A +{ + A() { return foo(); } // { dg-error "19:returning a value" } + ~A() { return foo(); } // { dg-error "20:returning a value" } + void bar() { return foo(); } // { dg-error "26:return-statement with a value" } +}; Index: testsuite/g++.dg/expr/pmf-1.C =================================================================== --- testsuite/g++.dg/expr/pmf-1.C (revision 278834) +++ testsuite/g++.dg/expr/pmf-1.C (working copy) @@ -13,7 +13,7 @@ struct A void h() { void (A::*p)() = &A::f; - void (A::*q)() = &(A::f); // { dg-error "parenthesized" } + void (A::*q)() = &(A::f); // { dg-error "27:ISO C\\+\\+ forbids taking the address of an unqualified or parenthesized" } foo(&g); // { dg-error "cannot convert" } } }; Index: testsuite/g++.dg/other/ptrmem2.C =================================================================== --- testsuite/g++.dg/other/ptrmem2.C (revision 278834) +++ testsuite/g++.dg/other/ptrmem2.C (working copy) @@ -19,7 +19,7 @@ template int f2(T x); int D::Foo () { - f1( &D::m); // { dg-error "cannot create pointer to ref" } + f1( &D::m); // { dg-error "11:cannot create pointer to ref" } f1( &(D::m)); // ok f2( &D::s); // ok f2( &(D::s)); // ok @@ -28,7 +28,7 @@ int D::Foo () int Foo () { - f1( &D::m); // { dg-error "cannot create pointer to ref" } + f1( &D::m); // { dg-error "11:cannot create pointer to ref" } f1( &(D::m)); // { dg-error "non-static" } f2( &D::s); // ok f2( &(D::s)); // ok Index: testsuite/g++.dg/template/ptrmem17.C =================================================================== --- testsuite/g++.dg/template/ptrmem17.C (revision 278834) +++ testsuite/g++.dg/template/ptrmem17.C (working copy) @@ -4,7 +4,7 @@ template struct A { int& i; A(); - ~A() { &A::i; } // { dg-error "reference" } + ~A() { &A::i; } // { dg-error "14:cannot create pointer to reference" } }; A<0> a; Index: testsuite/g++.old-deja/g++.bugs/900213_03.C =================================================================== --- testsuite/g++.old-deja/g++.bugs/900213_03.C (revision 278834) +++ testsuite/g++.old-deja/g++.bugs/900213_03.C (working copy) @@ -21,7 +21,7 @@ struct0 *ptr; void global_function_0 () { - fmp = &ptr->function_member; // { dg-error "" } + fmp = &ptr->function_member; // { dg-error "15:ISO C\\+\\+ forbids taking the address of a bound member function" } //dmp = &ptr->data_member; // caught by g++, missed by cfront } Index: testsuite/g++.old-deja/g++.other/pmf7.C =================================================================== --- testsuite/g++.old-deja/g++.other/pmf7.C (revision 278834) +++ testsuite/g++.old-deja/g++.other/pmf7.C (working copy) @@ -12,5 +12,5 @@ int main () { A a; &a.f; // { dg-error "" } overloaded - &a.g; // { dg-error "" } can't write a pmf like this + &a.g; // { dg-error "6:ISO C\\+\\+ forbids taking the address of a bound member function" } can't write a pmf like this } Index: testsuite/g++.old-deja/g++.other/ptrmem7.C =================================================================== --- testsuite/g++.old-deja/g++.other/ptrmem7.C (revision 278834) +++ testsuite/g++.old-deja/g++.other/ptrmem7.C (working copy) @@ -36,7 +36,7 @@ void A::foo () int (A::*ptr14) (int) = single; // { dg-error "cannot convert" } int (A::*ptr20) (int) = &(A::ns); // { dg-error "pointer to member" } - int (A::*ptr21) (int) = &(A::single); // { dg-error "pointer to member" } + int (A::*ptr21) (int) = &(A::single); // { dg-error "32:ISO C\\+\\+ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member" } int (*ptr31) (short) = &A::sole; int (*ptr32) (short) = A::sole;