pt.c (check_explicit_specialization): Use cp_expr_loc_or_input_loc.
/cp 2019-09-23 Paolo Carlini <paolo.carlini@oracle.com> * 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 <paolo.carlini@oracle.com> * 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
This commit is contained in:
parent
7926a220d8
commit
0788210f80
18 changed files with 93 additions and 48 deletions
|
@ -1,3 +1,12 @@
|
|||
2019-09-23 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* 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 <jason@redhat.com>
|
||||
|
||||
PR c++/91809 - bit-field and ellipsis.
|
||||
|
|
71
gcc/cp/pt.c
71
gcc/cp/pt.c
|
@ -2808,8 +2808,9 @@ check_explicit_specialization (tree declarator,
|
|||
/* This case handles bogus declarations like template <>
|
||||
template <class T> void f<int>(); */
|
||||
|
||||
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 <class T> void f<int>(); */
|
||||
|
||||
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))
|
||||
{
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
2019-09-23 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* 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 <sandra@codesourcery.com>
|
||||
|
||||
* lib/target-supports.exp
|
||||
|
|
|
@ -9,7 +9,7 @@ struct integral_constant
|
|||
integral_constant<bool, true> inst;
|
||||
|
||||
template <typename _Tp>
|
||||
struct integral_constant<bool, __is_enum(_Tp)> // { dg-error "" }
|
||||
struct integral_constant<bool, __is_enum(_Tp)> // { dg-error "32:template argument" }
|
||||
{
|
||||
};
|
||||
|
||||
|
|
|
@ -3,4 +3,4 @@ template<int... Values>
|
|||
struct int_vec {};
|
||||
|
||||
template<int... Values>
|
||||
struct int_vec<0, (Values+1)...> {}; // { dg-error "involves template parameter" }
|
||||
struct int_vec<0, (Values+1)...> {}; // { dg-error "26:template argument" }
|
||||
|
|
|
@ -8,7 +8,7 @@ template<int* p> class X { };
|
|||
template<const char *s> class Y {};
|
||||
template<const std::type_info &> 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<typeid(p)> z1; // { dg-error "" }
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
struct foo {
|
||||
template<typename T> void bar (T &t) {}
|
||||
template<> void bar<double>(double &t) {} // { dg-error "non-namespace|template|function" }
|
||||
template<> void bar<double>(double &t) {} // { dg-error "25:template-id .bar<double>. in declaration|explicit specialization" }
|
||||
};
|
||||
|
|
|
@ -6,4 +6,6 @@
|
|||
// substitution.
|
||||
|
||||
template <class T, class U> void foo(T, U) {}
|
||||
template <class T> void foo<T,void>(T, void) {} // { dg-error "incomplete|invalid|partial" }
|
||||
template <class T> void foo<T,void>(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 }
|
||||
|
|
|
@ -17,5 +17,6 @@ struct X
|
|||
template <class T>
|
||||
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 }
|
||||
};
|
||||
|
|
|
@ -26,14 +26,14 @@ int main()
|
|||
Message<s2> m2; // OK for clang since C++14, for gcc since C++17
|
||||
Message<s3> m3; // OK for clang/gcc since C++11
|
||||
|
||||
A<f2()> a1; // { dg-error "" "" { target c++14_down } }
|
||||
A<f2()> 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<s4> m4; // { dg-error "no linkage" "" { target c++14_down } }
|
||||
Message<s5> m5; // { dg-error "no linkage" "" { target c++14_down } }
|
||||
Message<f()> m6; // { dg-error "" "" { target c++14_down } }
|
||||
Message<B{}> m7; // { dg-error "" "" { target c++14_down } }
|
||||
Message<B{}> m7; // { dg-error "11:could not convert template argument" "" { target c++14_down } }
|
||||
|
||||
|
||||
char const s8[] = "hi";
|
||||
|
|
|
@ -16,7 +16,7 @@ template <int *PI>
|
|||
void dep6(bar<PI+1> *); // { dg-error "" "integral or enumeration" }
|
||||
|
||||
template <int I>
|
||||
void dep7(bar<I+1> *); // { dg-error "" }
|
||||
void dep7(bar<I+1> *); // { dg-error "16:could not convert template argument" }
|
||||
|
||||
template <int *PI>
|
||||
void dep8(foo< *PI > *); // { dg-error "" "integral or enumeration" }
|
||||
|
|
|
@ -6,8 +6,10 @@ template<int* p> 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
|
||||
|
||||
|
|
|
@ -21,4 +21,4 @@ template<typename T, T V>
|
|||
struct Z { };
|
||||
|
||||
template<typename T>
|
||||
struct Z<T, (T)0> { }; // { dg-error "involves template parameter" }
|
||||
struct Z<T, (T)0> { }; // { dg-error "13:template argument" }
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
struct A
|
||||
{
|
||||
template<int> 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" }
|
||||
};
|
||||
|
|
|
@ -10,7 +10,8 @@ template <class C>
|
|||
struct S2
|
||||
{
|
||||
template <class T>
|
||||
void f<S1<T> >(T) {} // { dg-error "" } bad specialization.
|
||||
void f<S1<T> >(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 }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
template <class T>
|
||||
struct S {
|
||||
template <class U> void f(U);
|
||||
template <> void f<int>(int); // { dg-error "" } invalid specialization
|
||||
template <> void f<int>(int); // { dg-error "20:template-id .f<int>. in declaration|explicit specialization" }
|
||||
|
||||
template <class V> struct I {}; // { dg-error "template" }
|
||||
template <class V> struct I<V*> {}; // { dg-error "template" }
|
||||
|
|
|
@ -4,8 +4,8 @@ template <class T> struct S {};
|
|||
template <class T = int> struct S<T*> {}; // { dg-error "" } default argument
|
||||
|
||||
template <int I, int J> struct A {};
|
||||
template <int I> struct A<I+5, I*2> {}; // { dg-error "" } argument involves parameter
|
||||
|
||||
template <int I> struct A<I+5, I*2> {}; // { dg-error "28:template argument" }
|
||||
// { dg-error "33:template argument" "" { target *-*-* } .-1 }
|
||||
template <class T, T t> struct C {};
|
||||
template <class T> struct C<T, 1>; // { dg-error "" } type depends on parameter
|
||||
int i;
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
template <int nlimb, int i>
|
||||
inline unsigned f (unsigned* ptr);
|
||||
template <int nlimb>
|
||||
inline unsigned f<nlimb,nlimb> (unsigned* ptr) // { dg-error "partial specialization" }
|
||||
inline unsigned f<nlimb,nlimb> (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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue