]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up mangling ICE with void{} [PR106863]
authorJakub Jelinek <jakub@redhat.com>
Fri, 21 Oct 2022 07:00:41 +0000 (09:00 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 21 Oct 2022 07:00:41 +0000 (09:00 +0200)
We ICE on the following testcase during mangling, finish_compound_literal
returns for void{} void_node and the mangler doesn't handle it.
Handling void_node in the mangler seems problematic to me, because
we don't know for which case it has been created.
The following patch arranges to mangle it as other compound literals
with no operands, so it demangles as void{}, by returning a void type
COMPOUND_LITERAL_P with no elements if processing_template_decl.
Otherwise it keeps returning void_node.

2022-10-21  Jakub Jelinek  <jakub@redhat.com>

PR c++/106863
* semantics.cc (finish_compound_literal): For void{}, if
processing_template_decl return a COMPOUND_LITERAL_P
CONSTRUCTOR rather than void_node.

* g++.dg/cpp0x/dr2351-2.C: New test.

gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp0x/dr2351-2.C [new file with mode: 0644]

index 7d46c3c2db94cb1e0028be75e7d3dd976004483c..82f9dd8dd4e662ca6b79bfb9dea4e4815e5c3644 100644 (file)
@@ -3164,7 +3164,14 @@ finish_compound_literal (tree type, tree compound_literal,
     {
       /* DR2351 */
       if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0)
-       return void_node;
+       {
+         if (!processing_template_decl)
+           return void_node;
+         TREE_TYPE (compound_literal) = type;
+         TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
+         CONSTRUCTOR_IS_DEPENDENT (compound_literal) = 0;
+         return compound_literal;
+       }
       else if (VOID_TYPE_P (type)
               && processing_template_decl
               && maybe_zero_constructor_nelts (compound_literal))
diff --git a/gcc/testsuite/g++.dg/cpp0x/dr2351-2.C b/gcc/testsuite/g++.dg/cpp0x/dr2351-2.C
new file mode 100644 (file)
index 0000000..deb1718
--- /dev/null
@@ -0,0 +1,16 @@
+// DR2351
+// { dg-do compile { target c++11 } }
+
+void bar (int);
+
+template <typename T>
+auto foo (T t) -> decltype (bar (t), void{})
+{
+  return bar (t);
+}
+
+int
+main ()
+{
+  foo (0);
+}