From patchwork Mon Sep 23 11:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1165986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509442-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="X7TSuEPD"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="aejGmDdE"; 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 46cM5p6bLPz9sP3 for ; Mon, 23 Sep 2019 21:09:16 +1000 (AEST) 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=qQtxYGEA4I9/Z+Doi+S7VQs7nGqvxHkhKtnXEu9Qrqh8VwiLOe BesLU+tEGE+WdPLYl3lN+ET59uUL0fafTbewiB9HN4zgsnRP2hE6HzPBHYcCPSbI Ge4qL0bLMEKaN9SmiqTm7wH/YtFdvd+WV5fIO+wapwrl/5Ez7E85rFK+U= 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=visPpJe9aDH+NfzoXqh5pdekQOc=; b=X7TSuEPD4lkvVOtSvb+d lt9xttvjaSgMuWYyzGhmJJoefEPiSZ6C9dFg1uIIaWXbDQcMLICNPpwZ9GKg7ypF RpurncaLjS+swy3SrNCkSITnXP0lpCWMLWny6ce/EX7Kk9FdB4kLdzruhmv1njpl nwGqfG6TAq0ncZasMYEbLzs= Received: (qmail 75955 invoked by alias); 23 Sep 2019 11:09:08 -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 75947 invoked by uid 89); 23 Sep 2019 11:09:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.5 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=dealing, complain, tsubst_flags_t, linkage X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Sep 2019 11:09:05 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8NAxORW083663; Mon, 23 Sep 2019 11:09:02 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=bKu0n+fT4qUPlFIECaoiC6ExnjN+LJsRBEVgdBt9T/8=; b=aejGmDdEDmefzxjlnhqeMfvN/jcgTDthdPrPDilNElbC162CF0fNx25OMkrwuhka7zAj oEbTEL1EmaXe0tuxyeD5HTJ+34o4lzyVaLC8Y6aTIli70B7x4EGr+LtCKcFboQ1/WGUD mrr4SS/9GBfiRParCFMgqIpNk/1Gn0b9MDDBEKvkKFipHsiXXAbX+hcbPPBLqJCEyA4J o5XkhRbUleebcofll9yi+RQ+oTJ3KCjVwDyarmJXCpGGRbF7HIEKNZIHgAB1aleiLuB7 642onwovwD3SpbaOfn1vPNYF/yBaUdbN+6Z6LrdrOBxZPdWad0fDv9zxKh4BVnzT4y6G eQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2v5btpp752-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2019 11:09:02 +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 x8NB7LfV189727; Mon, 23 Sep 2019 11:09:01 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2v6acv9d4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2019 11:09:01 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x8NB8xQi028278; Mon, 23 Sep 2019 11:08:59 GMT Received: from [192.168.1.4] (/87.3.30.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 23 Sep 2019 04:08:58 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Use cp_expr_loc_or_input_loc in a few places in pt.c Message-ID: Date: Mon, 23 Sep 2019 13:08:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, simply a few new uses, in the places where we are dealing with expressions: we are able to do the right thing in a pretty large number of additional cases - the below could even include more testcases, most however are rather tangled (eg, we finally get the locations completely right only for the c++17 errors, there are additional errors on the same line, a few redundant ones, etc). Tested x86_64-linux, as usual. Thanks, Paolo. //////////////////////// /cp 2019-09-23 Paolo Carlini * pt.c (check_explicit_specialization): Use cp_expr_loc_or_input_loc. (process_partial_specialization): Likewise. (convert_nontype_argument_function): Likewise. (invalid_tparm_referent_p): Likewise. (convert_template_argument): Likewise. (check_valid_ptrmem_cst_expr): Tidy. /testsuite 2019-09-23 Paolo Carlini * g++.dg/cpp0x/pr68724.C: Check location(s) too. * g++.dg/cpp0x/variadic38.C: Likewise. * g++.dg/cpp1z/nontype2.C: Likewise. * g++.dg/parse/explicit1.C: Likewise. * g++.dg/template/crash11.C: Likewise. * g++.dg/template/non-dependent8.C: Likewise. * g++.dg/template/nontype-array1.C: Likewise. * g++.dg/template/nontype3.C: Likewise. * g++.dg/template/nontype8.C: Likewise. * g++.dg/template/partial5.C: Likewise. * g++.dg/template/spec33.C: Likewise. * g++.old-deja/g++.pt/memtemp64.C: Likewise. * g++.old-deja/g++.pt/spec20.C: Likewise. * g++.old-deja/g++.pt/spec21.C: Likewise. * g++.old-deja/g++.robertl/eb103.C: Likewise. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 276015) +++ cp/pt.c (working copy) @@ -2808,8 +2808,9 @@ check_explicit_specialization (tree declarator, /* This case handles bogus declarations like template <> template void f(); */ - error ("template-id %qD in declaration of primary template", - declarator); + error_at (cp_expr_loc_or_input_loc (declarator), + "template-id %qE in declaration of primary template", + declarator); return decl; } } @@ -2867,8 +2868,9 @@ check_explicit_specialization (tree declarator, template void f(); */ if (!uses_template_parms (TREE_OPERAND (declarator, 1))) - error ("template-id %qD in declaration of primary template", - declarator); + error_at (cp_expr_loc_or_input_loc (declarator), + "template-id %qE in declaration of primary template", + declarator); else if (variable_template_p (TREE_OPERAND (declarator, 0))) { /* Partial specialization of variable template. */ @@ -2877,11 +2879,13 @@ check_explicit_specialization (tree declarator, goto ok; } else if (cxx_dialect < cxx14) - error ("non-type partial specialization %qD " - "is not allowed", declarator); + error_at (cp_expr_loc_or_input_loc (declarator), + "non-type partial specialization %qE " + "is not allowed", declarator); else - error ("non-class, non-variable partial specialization %qD " - "is not allowed", declarator); + error_at (cp_expr_loc_or_input_loc (declarator), + "non-class, non-variable partial specialization %qE " + "is not allowed", declarator); return decl; ok:; } @@ -4958,8 +4962,9 @@ process_partial_specialization (tree decl) { if ((!packed_args && tpd.arg_uses_template_parms[i]) || (packed_args && uses_template_parms (arg))) - error ("template argument %qE involves template parameter(s)", - arg); + error_at (cp_expr_loc_or_input_loc (arg), + "template argument %qE involves template " + "parameter(s)", arg); else { /* Look at the corresponding template parameter, @@ -6258,13 +6263,14 @@ convert_nontype_argument_function (tree type, tree { if (complain & tf_error) { - error ("%qE is not a valid template argument for type %qT", - expr, type); + location_t loc = cp_expr_loc_or_input_loc (expr); + error_at (loc, "%qE is not a valid template argument for type %qT", + expr, type); if (TYPE_PTR_P (type)) - inform (input_location, "it must be the address of a function " + inform (loc, "it must be the address of a function " "with external linkage"); else - inform (input_location, "it must be the name of a function with " + inform (loc, "it must be the name of a function with " "external linkage"); } return NULL_TREE; @@ -6275,14 +6281,15 @@ convert_nontype_argument_function (tree type, tree { if (complain & tf_error) { + location_t loc = cp_expr_loc_or_input_loc (expr); if (cxx_dialect >= cxx11) - error ("%qE is not a valid template argument for type %qT " - "because %qD has no linkage", - expr, type, fn_no_ptr); + error_at (loc, "%qE is not a valid template argument for type " + "%qT because %qD has no linkage", + expr, type, fn_no_ptr); else - error ("%qE is not a valid template argument for type %qT " - "because %qD does not have external linkage", - expr, type, fn_no_ptr); + error_at (loc, "%qE is not a valid template argument for type " + "%qT because %qD does not have external linkage", + expr, type, fn_no_ptr); } return NULL_TREE; } @@ -6309,7 +6316,6 @@ static bool check_valid_ptrmem_cst_expr (tree type, tree expr, tsubst_flags_t complain) { - location_t loc = cp_expr_loc_or_input_loc (expr); tree orig_expr = expr; STRIP_NOPS (expr); if (null_ptr_cst_p (expr)) @@ -6326,6 +6332,7 @@ check_valid_ptrmem_cst_expr (tree type, tree expr, return true; if (complain & tf_error) { + location_t loc = cp_expr_loc_or_input_loc (orig_expr); error_at (loc, "%qE is not a valid template argument for type %qT", orig_expr, type); if (TREE_CODE (expr) != PTRMEM_CST) @@ -6623,16 +6630,18 @@ invalid_tparm_referent_p (tree type, tree expr, ts if (!VAR_P (decl)) { if (complain & tf_error) - error ("%qE is not a valid template argument of type %qT " - "because %qE is not a variable", expr, type, decl); + error_at (cp_expr_loc_or_input_loc (expr), + "%qE is not a valid template argument of type %qT " + "because %qE is not a variable", expr, type, decl); return true; } else if (cxx_dialect < cxx11 && !DECL_EXTERNAL_LINKAGE_P (decl)) { if (complain & tf_error) - error ("%qE is not a valid template argument of type %qT " - "in C++98 because %qD does not have external linkage", - expr, type, decl); + error_at (cp_expr_loc_or_input_loc (expr), + "%qE is not a valid template argument of type %qT " + "in C++98 because %qD does not have external linkage", + expr, type, decl); return true; } else if ((cxx_dialect >= cxx11 && cxx_dialect < cxx17) @@ -6639,8 +6648,9 @@ invalid_tparm_referent_p (tree type, tree expr, ts && decl_linkage (decl) == lk_none) { if (complain & tf_error) - error ("%qE is not a valid template argument of type %qT " - "because %qD has no linkage", expr, type, decl); + error_at (cp_expr_loc_or_input_loc (expr), + "%qE is not a valid template argument of type %qT " + "because %qD has no linkage", expr, type, decl); return true; } /* C++17: For a non-type template-parameter of reference or pointer @@ -8129,8 +8139,9 @@ convert_template_argument (tree parm, if (val == NULL_TREE) val = error_mark_node; else if (val == error_mark_node && (complain & tf_error)) - error ("could not convert template argument %qE from %qT to %qT", - orig_arg, TREE_TYPE (orig_arg), t); + error_at (cp_expr_loc_or_input_loc (orig_arg), + "could not convert template argument %qE from %qT to %qT", + orig_arg, TREE_TYPE (orig_arg), t); if (INDIRECT_REF_P (val)) { Index: testsuite/g++.dg/cpp0x/pr68724.C =================================================================== --- testsuite/g++.dg/cpp0x/pr68724.C (revision 276015) +++ testsuite/g++.dg/cpp0x/pr68724.C (working copy) @@ -9,7 +9,7 @@ struct integral_constant integral_constant inst; template -struct integral_constant // { dg-error "" } +struct integral_constant // { dg-error "32:template argument" } { }; Index: testsuite/g++.dg/cpp0x/variadic38.C =================================================================== --- testsuite/g++.dg/cpp0x/variadic38.C (revision 276015) +++ testsuite/g++.dg/cpp0x/variadic38.C (working copy) @@ -3,4 +3,4 @@ template struct int_vec {}; template -struct int_vec<0, (Values+1)...> {}; // { dg-error "involves template parameter" } +struct int_vec<0, (Values+1)...> {}; // { dg-error "26:template argument" } Index: testsuite/g++.dg/cpp1z/nontype2.C =================================================================== --- testsuite/g++.dg/cpp1z/nontype2.C (revision 276015) +++ testsuite/g++.dg/cpp1z/nontype2.C (working copy) @@ -8,7 +8,7 @@ template class X { }; template class Y {}; template class Z {}; -X<&s.m> x7; // { dg-error "" } +X<&s.m> x7; // { dg-error "3:.& s.S::m. is not a valid template argument" } Y<"foo"> y1; // { dg-error "string literal" } Z z1; // { dg-error "" } Index: testsuite/g++.dg/parse/explicit1.C =================================================================== --- testsuite/g++.dg/parse/explicit1.C (revision 276015) +++ testsuite/g++.dg/parse/explicit1.C (working copy) @@ -7,5 +7,5 @@ struct foo { template void bar (T &t) {} - template<> void bar(double &t) {} // { dg-error "non-namespace|template|function" } + template<> void bar(double &t) {} // { dg-error "25:template-id .bar. in declaration|explicit specialization" } }; Index: testsuite/g++.dg/template/crash11.C =================================================================== --- testsuite/g++.dg/template/crash11.C (revision 276015) +++ testsuite/g++.dg/template/crash11.C (working copy) @@ -6,4 +6,6 @@ // substitution. template void foo(T, U) {} -template void foo(T, void) {} // { dg-error "incomplete|invalid|partial" } +template void foo(T, void) {} // { dg-error "40:invalid use of type .void." } +// { dg-error "25:non-class, non-variable partial specialization" "" { target c++14 } .-1 } +// { dg-error "25:non-type partial specialization" "" { target c++11_down } .-2 } Index: testsuite/g++.dg/template/non-dependent8.C =================================================================== --- testsuite/g++.dg/template/non-dependent8.C (revision 276015) +++ testsuite/g++.dg/template/non-dependent8.C (working copy) @@ -17,5 +17,6 @@ struct X template struct Foo { - X<&S::i> x; // { dg-error "convert|no type" } + X<&S::i> x; // { dg-error "5:could not convert" "" { target c++17 } } + // { dg-error "could not convert" "" { target c++14_down } .-1 } }; Index: testsuite/g++.dg/template/nontype-array1.C =================================================================== --- testsuite/g++.dg/template/nontype-array1.C (revision 276015) +++ testsuite/g++.dg/template/nontype-array1.C (working copy) @@ -26,7 +26,7 @@ int main() Message m2; // OK for clang since C++14, for gcc since C++17 Message m3; // OK for clang/gcc since C++11 - A a1; // { dg-error "" "" { target c++14_down } } + A a1; // { dg-error "7:.f2\\(\\). is not a valid template argument" "" { target c++14_down } } static char const s4[] = "hi"; static constexpr char const s5[] = "hi"; // OK since C++11 @@ -33,7 +33,7 @@ int main() Message m4; // { dg-error "no linkage" "" { target c++14_down } } Message m5; // { dg-error "no linkage" "" { target c++14_down } } Message m6; // { dg-error "" "" { target c++14_down } } - Message m7; // { dg-error "" "" { target c++14_down } } + Message m7; // { dg-error "11:could not convert template argument" "" { target c++14_down } } char const s8[] = "hi"; Index: testsuite/g++.dg/template/nontype3.C =================================================================== --- testsuite/g++.dg/template/nontype3.C (revision 276015) +++ testsuite/g++.dg/template/nontype3.C (working copy) @@ -16,7 +16,7 @@ template void dep6(bar *); // { dg-error "" "integral or enumeration" } template -void dep7(bar *); // { dg-error "" } +void dep7(bar *); // { dg-error "16:could not convert template argument" } template void dep8(foo< *PI > *); // { dg-error "" "integral or enumeration" } Index: testsuite/g++.dg/template/nontype8.C =================================================================== --- testsuite/g++.dg/template/nontype8.C (revision 276015) +++ testsuite/g++.dg/template/nontype8.C (working copy) @@ -6,8 +6,10 @@ template class X { }; int a[10]; struct S { int m; static int s; } s; -X<&a[2]> x3; // { dg-error "" } address of array element -X<&s.m> x4; // { dg-error "" } address of non-static member +X<&a[2]> x3; // { dg-error "3:.& a\\\[2\\\]. is not a valid template argument" "" { target c++17 } } +// { dg-error "" "" { target c++14_down } .-1 } +X<&s.m> x4; // { dg-error "3:.& s.S::m. is not a valid template argument" "" { target c++17 } } +// { dg-error "" "" { target c++14_down } .-1 } X<&s.s> x5; // { dg-error "" "" { target { ! c++17 } } } &S::s must be used X<&S::s> x6; // OK: address of static member Index: testsuite/g++.dg/template/partial5.C =================================================================== --- testsuite/g++.dg/template/partial5.C (revision 276015) +++ testsuite/g++.dg/template/partial5.C (working copy) @@ -21,4 +21,4 @@ template struct Z { }; template -struct Z { }; // { dg-error "involves template parameter" } +struct Z { }; // { dg-error "13:template argument" } Index: testsuite/g++.dg/template/spec33.C =================================================================== --- testsuite/g++.dg/template/spec33.C (revision 276015) +++ testsuite/g++.dg/template/spec33.C (working copy) @@ -3,5 +3,5 @@ struct A { template static void foo () {} - template<> static void foo<0>() {} // { dg-error "explicit|template" } + template<> static void foo<0>() {} // { dg-error "31:template-id .foo<0>. in declaration|explicit specialization" } }; Index: testsuite/g++.old-deja/g++.pt/memtemp64.C =================================================================== --- testsuite/g++.old-deja/g++.pt/memtemp64.C (revision 276015) +++ testsuite/g++.old-deja/g++.pt/memtemp64.C (working copy) @@ -10,7 +10,8 @@ template struct S2 { template - void f >(T) {} // { dg-error "" } bad specialization. + void f >(T) {} // { dg-error "8:non-class, non-variable partial specialization" "" { target c++14 } } + // { dg-error "8:non-type partial specialization" "" { target c++11_down } .-1 } }; Index: testsuite/g++.old-deja/g++.pt/spec20.C =================================================================== --- testsuite/g++.old-deja/g++.pt/spec20.C (revision 276015) +++ testsuite/g++.old-deja/g++.pt/spec20.C (working copy) @@ -8,7 +8,7 @@ template struct S { template void f(U); - template <> void f(int); // { dg-error "" } invalid specialization + template <> void f(int); // { dg-error "20:template-id .f. in declaration|explicit specialization" } template struct I {}; // { dg-error "template" } template struct I {}; // { dg-error "template" } Index: testsuite/g++.old-deja/g++.pt/spec21.C =================================================================== --- testsuite/g++.old-deja/g++.pt/spec21.C (revision 276015) +++ testsuite/g++.old-deja/g++.pt/spec21.C (working copy) @@ -4,8 +4,8 @@ template struct S {}; template struct S {}; // { dg-error "" } default argument template struct A {}; -template struct A {}; // { dg-error "" } argument involves parameter - +template struct A {}; // { dg-error "28:template argument" } +// { dg-error "33:template argument" "" { target *-*-* } .-1 } template struct C {}; template struct C; // { dg-error "" } type depends on parameter int i; Index: testsuite/g++.old-deja/g++.robertl/eb103.C =================================================================== --- testsuite/g++.old-deja/g++.robertl/eb103.C (revision 276015) +++ testsuite/g++.old-deja/g++.robertl/eb103.C (working copy) @@ -4,7 +4,8 @@ template inline unsigned f (unsigned* ptr); template -inline unsigned f (unsigned* ptr) // { dg-error "partial specialization" } +inline unsigned f (unsigned* ptr) // { dg-error "17:non-class, non-variable partial specialization" "" { target c++14 } } +// { dg-error "17:non-type partial specialization" "" { target c++11_down } .-1 } { return 1; }