]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
pt.c (convert_template_argument): Add a diagnostic for the [temp.arg]/2 ambiguity...
authorMarek Polacek <polacek@redhat.com>
Mon, 20 May 2019 18:59:05 +0000 (18:59 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 20 May 2019 18:59:05 +0000 (18:59 +0000)
* 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
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/nontype-class17.C [new file with mode: 0644]

index 0c284d4591f9209d34e9e3c924dd06b56a98b613..87ecd7c1f6fcf5bd3e0562ecb1bec69399a18b51 100644 (file)
@@ -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.
index 97d8f08c94d912877000ecfe6e5538691f8f0de0..3519c7a34a6ea9e23d1d8708b4370aa86cfa613e 100644 (file)
@@ -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);
index 3fefc0ebd5f56f1665d3bb874000b7ad0194c938..0f4c81c21546eeba13c2ab876f79dca565cc9633 100644 (file)
@@ -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 (file)
index 0000000..ca5f68e
--- /dev/null
@@ -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;
+}