]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with unnamed tparm and concept [PR103408]
authorMarek Polacek <polacek@redhat.com>
Tue, 30 Nov 2021 21:43:19 +0000 (16:43 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 2 Dec 2021 13:11:39 +0000 (08:11 -0500)
Here we crash when issuing the "constraint C has type T, not bool"
error, because pp_cxx_parameter_mapping wasn't prepared to see an
anonymous template parameter.  With this patch we print

error: constraint 'auto(<lambda>) [with <unnamed> = 0]' has type '<lambda()>', not 'bool'

The "<unnamed>" is what this patch adds.

PR c++/103408

gcc/cp/ChangeLog:

* cxx-pretty-print.c (pp_cxx_parameter_mapping): Print "<unnamed>"
rather than crash on an unnamed template parameter.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/concepts-err1.C: New test.

gcc/cp/cxx-pretty-print.c
gcc/testsuite/g++.dg/cpp23/concepts-err1.C [new file with mode: 0644]

index 25cabfee39fca6f7a5ac90502fdf9612c1506559..3ea357deb80cb0a3f51df5cfcd1e9328f5ad1463 100644 (file)
@@ -2891,8 +2891,10 @@ pp_cxx_parameter_mapping (cxx_pretty_printer *pp, tree map)
 
       if (TYPE_P (parm))
        pp->type_id (parm);
+      else if (tree name = DECL_NAME (TEMPLATE_PARM_DECL (parm)))
+       pp_cxx_tree_identifier (pp, name);
       else
-       pp_cxx_tree_identifier (pp, DECL_NAME (TEMPLATE_PARM_DECL (parm)));
+       pp->translate_string ("<unnamed>");
 
       pp_cxx_whitespace (pp);
       pp_equal (pp);
diff --git a/gcc/testsuite/g++.dg/cpp23/concepts-err1.C b/gcc/testsuite/g++.dg/cpp23/concepts-err1.C
new file mode 100644 (file)
index 0000000..e5bdc54
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/103408
+// { dg-do compile { target c++23 } }
+
+template<int>
+concept C = auto([]{}); // { dg-error "constraint" }
+static_assert(C<0>); // { dg-error "non-constant condition for static assertion" }