From 8d25372f16eb18581227790389df3115314d07ab Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 20 May 2019 18:59:05 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 20 ++++++++++++++++---- gcc/testsuite/ChangeLog | 2 ++ gcc/testsuite/g++.dg/cpp2a/nontype-class17.C | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class17.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0c284d4591f..87ecd7c1f6f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-05-20 Marek Polacek + + * pt.c (convert_template_argument): Add a diagnostic for the + [temp.arg]/2 ambiguity case. + 2019-05-20 Paolo Carlini * cp-tree.h: Remove remnants of CONV_NONCONVERTING. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 97d8f08c94d..3519c7a34a6 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 3fefc0ebd5f..0f4c81c2154 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 * 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 00000000000..ca5f68e1611 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class17.C @@ -0,0 +1,17 @@ +// { dg-do compile { target c++2a } } + +template +struct S { }; + +struct R { }; + +void +g (void) +{ + S s; // { dg-error "mismatch" } +// { dg-message "treated as function" "note" { target *-*-* } .-1 } + S s2; + S s3; // { dg-error "mismatch" } +// { dg-message "treated as function" "note" { target *-*-* } .-1 } + S s4; +} -- 2.30.2