From 0788210f804a2ba451bc9cbda26c256ad9f7c5f3 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 23 Sep 2019 19:29:55 +0000 Subject: [PATCH] pt.c (check_explicit_specialization): Use cp_expr_loc_or_input_loc. /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. From-SVN: r276064 --- gcc/cp/ChangeLog | 9 +++ gcc/cp/pt.c | 71 +++++++++++-------- gcc/testsuite/ChangeLog | 18 +++++ gcc/testsuite/g++.dg/cpp0x/pr68724.C | 2 +- gcc/testsuite/g++.dg/cpp0x/variadic38.C | 2 +- gcc/testsuite/g++.dg/cpp1z/nontype2.C | 2 +- gcc/testsuite/g++.dg/parse/explicit1.C | 2 +- gcc/testsuite/g++.dg/template/crash11.C | 4 +- .../g++.dg/template/non-dependent8.C | 3 +- .../g++.dg/template/nontype-array1.C | 4 +- gcc/testsuite/g++.dg/template/nontype3.C | 2 +- gcc/testsuite/g++.dg/template/nontype8.C | 6 +- gcc/testsuite/g++.dg/template/partial5.C | 2 +- gcc/testsuite/g++.dg/template/spec33.C | 2 +- gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C | 3 +- gcc/testsuite/g++.old-deja/g++.pt/spec20.C | 2 +- gcc/testsuite/g++.old-deja/g++.pt/spec21.C | 4 +- .../g++.old-deja/g++.robertl/eb103.C | 3 +- 18 files changed, 93 insertions(+), 48 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 541d018b53e..5b561e6bdbb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +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. + 2019-09-23 Jason Merrill PR c++/91809 - bit-field and ellipsis. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4b3993cdeda..e5d64989b32 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 expr, { 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 expr, { 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,24 +6630,27 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain) 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) && 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)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a9b108db1dd..6d84a01e541 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,21 @@ +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. + 2019-09-23 Sandra Loosemore * lib/target-supports.exp diff --git a/gcc/testsuite/g++.dg/cpp0x/pr68724.C b/gcc/testsuite/g++.dg/cpp0x/pr68724.C index ff6d84dc3f7..4e99d53d5a9 100644 --- a/gcc/testsuite/g++.dg/cpp0x/pr68724.C +++ b/gcc/testsuite/g++.dg/cpp0x/pr68724.C @@ -9,7 +9,7 @@ struct integral_constant integral_constant inst; template -struct integral_constant // { dg-error "" } +struct integral_constant // { dg-error "32:template argument" } { }; diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic38.C b/gcc/testsuite/g++.dg/cpp0x/variadic38.C index 62031a3d001..b569404cdf2 100644 --- a/gcc/testsuite/g++.dg/cpp0x/variadic38.C +++ b/gcc/testsuite/g++.dg/cpp0x/variadic38.C @@ -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" } diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype2.C b/gcc/testsuite/g++.dg/cpp1z/nontype2.C index 393c8332c76..75dc7600379 100644 --- a/gcc/testsuite/g++.dg/cpp1z/nontype2.C +++ b/gcc/testsuite/g++.dg/cpp1z/nontype2.C @@ -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 "" } diff --git a/gcc/testsuite/g++.dg/parse/explicit1.C b/gcc/testsuite/g++.dg/parse/explicit1.C index 35358749e1d..23c82649ded 100644 --- a/gcc/testsuite/g++.dg/parse/explicit1.C +++ b/gcc/testsuite/g++.dg/parse/explicit1.C @@ -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" } }; diff --git a/gcc/testsuite/g++.dg/template/crash11.C b/gcc/testsuite/g++.dg/template/crash11.C index 3c69514e243..229aec9ffe2 100644 --- a/gcc/testsuite/g++.dg/template/crash11.C +++ b/gcc/testsuite/g++.dg/template/crash11.C @@ -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 } diff --git a/gcc/testsuite/g++.dg/template/non-dependent8.C b/gcc/testsuite/g++.dg/template/non-dependent8.C index 369e137317c..f99691bdc3a 100644 --- a/gcc/testsuite/g++.dg/template/non-dependent8.C +++ b/gcc/testsuite/g++.dg/template/non-dependent8.C @@ -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 } }; diff --git a/gcc/testsuite/g++.dg/template/nontype-array1.C b/gcc/testsuite/g++.dg/template/nontype-array1.C index f22551b0f1a..2a227b948b3 100644 --- a/gcc/testsuite/g++.dg/template/nontype-array1.C +++ b/gcc/testsuite/g++.dg/template/nontype-array1.C @@ -26,14 +26,14 @@ 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 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"; diff --git a/gcc/testsuite/g++.dg/template/nontype3.C b/gcc/testsuite/g++.dg/template/nontype3.C index 2269e0faca3..0f5accf5b19 100644 --- a/gcc/testsuite/g++.dg/template/nontype3.C +++ b/gcc/testsuite/g++.dg/template/nontype3.C @@ -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" } diff --git a/gcc/testsuite/g++.dg/template/nontype8.C b/gcc/testsuite/g++.dg/template/nontype8.C index 86d39f3744d..b4fbeaed2d8 100644 --- a/gcc/testsuite/g++.dg/template/nontype8.C +++ b/gcc/testsuite/g++.dg/template/nontype8.C @@ -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 diff --git a/gcc/testsuite/g++.dg/template/partial5.C b/gcc/testsuite/g++.dg/template/partial5.C index 464408e4a66..a56229770f4 100644 --- a/gcc/testsuite/g++.dg/template/partial5.C +++ b/gcc/testsuite/g++.dg/template/partial5.C @@ -21,4 +21,4 @@ template struct Z { }; template -struct Z { }; // { dg-error "involves template parameter" } +struct Z { }; // { dg-error "13:template argument" } diff --git a/gcc/testsuite/g++.dg/template/spec33.C b/gcc/testsuite/g++.dg/template/spec33.C index 7b7a7519829..2cdf85bbbb5 100644 --- a/gcc/testsuite/g++.dg/template/spec33.C +++ b/gcc/testsuite/g++.dg/template/spec33.C @@ -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" } }; diff --git a/gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C b/gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C index dda0a63b440..47b4ded2c24 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C @@ -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 } }; diff --git a/gcc/testsuite/g++.old-deja/g++.pt/spec20.C b/gcc/testsuite/g++.old-deja/g++.pt/spec20.C index b6148e5ded9..610e6c73371 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/spec20.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/spec20.C @@ -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" } diff --git a/gcc/testsuite/g++.old-deja/g++.pt/spec21.C b/gcc/testsuite/g++.old-deja/g++.pt/spec21.C index 4107306d1d4..cf89d6b325a 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/spec21.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/spec21.C @@ -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; diff --git a/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C b/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C index ffc51ee4411..de181ab1ac2 100644 --- a/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C +++ b/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C @@ -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; } -- 2.30.2