diff options
author | Marek Polacek <polacek@redhat.com> | 2019-05-20 18:59:05 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-05-20 18:59:05 +0000 |
commit | 8d25372f16eb18581227790389df3115314d07ab (patch) | |
tree | 5e4dfcf6439a49db1583cbd2e9e35cfdee01406b /gcc | |
parent | 215826720508c828b6a5eaca7f0a7396d78ab36b (diff) | |
download | gcc-8d25372f16eb18581227790389df3115314d07ab.zip gcc-8d25372f16eb18581227790389df3115314d07ab.tar.gz gcc-8d25372f16eb18581227790389df3115314d07ab.tar.bz2 |
pt.c (convert_template_argument): Add a diagnostic for the [temp.arg]/2 ambiguity case.
* pt.c (convert_template_argument): Add a diagnostic for the
[temp.arg]/2 ambiguity case.
* g++.dg/cpp2a/nontype-class17.C: New test.
From-SVN: r271431
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/pt.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/nontype-class17.C | 17 |
4 files changed, 40 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0c284d4..87ecd7c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-05-20 Marek Polacek <polacek@redhat.com> + + * pt.c (convert_template_argument): Add a diagnostic for the + [temp.arg]/2 ambiguity case. + 2019-05-20 Paolo Carlini <paolo.carlini@oracle.com> * cp-tree.h: Remove remnants of CONV_NONCONVERTING. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 97d8f08..3519c7a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7963,10 +7963,22 @@ convert_template_argument (tree parm, "parameter list for %qD", i + 1, in_decl); if (is_type) - inform (input_location, - " expected a constant of type %qT, got %qT", - TREE_TYPE (parm), - (DECL_P (arg) ? DECL_NAME (arg) : orig_arg)); + { + /* The template argument is a type, but we're expecting + an expression. */ + inform (input_location, + " expected a constant of type %qT, got %qT", + TREE_TYPE (parm), + (DECL_P (arg) ? DECL_NAME (arg) : orig_arg)); + /* [temp.arg]/2: "In a template-argument, an ambiguity + between a type-id and an expression is resolved to a + type-id, regardless of the form of the corresponding + template-parameter." So give the user a clue. */ + if (TREE_CODE (arg) == FUNCTION_TYPE) + inform (input_location, " ambiguous template argument " + "for non-type template parameter is treated as " + "function type"); + } else if (requires_tmpl_type) inform (input_location, " expected a class template, got %qE", orig_arg); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3fefc0e..0f4c81c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -2,6 +2,8 @@ * g++.dg/ext/utf8-2.C: Accept both "char" and "char8_t" in aka. + * g++.dg/cpp2a/nontype-class17.C: New test. + 2019-05-20 Jeff Law <law@redhat.com> * gcc.dg/Wtype-limits-Wextra.c: Adjust expected output after diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class17.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class17.C new file mode 100644 index 0000000..ca5f68e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class17.C @@ -0,0 +1,17 @@ +// { dg-do compile { target c++2a } } + +template<auto> +struct S { }; + +struct R { }; + +void +g (void) +{ + S<R()> s; // { dg-error "mismatch" } +// { dg-message "treated as function" "note" { target *-*-* } .-1 } + S<R{}> s2; + S<int()> s3; // { dg-error "mismatch" } +// { dg-message "treated as function" "note" { target *-*-* } .-1 } + S<int{}> s4; +} |