public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3429] c++: Fix up mangling ICE with void{} [PR106863]
@ 2022-10-21  7:03 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-10-21  7:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5f9fac6ca86458ef21ab91ca471429d63f954003

commit r13-3429-g5f9fac6ca86458ef21ab91ca471429d63f954003
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Oct 21 09:00:41 2022 +0200

    c++: Fix up mangling ICE with void{} [PR106863]
    
    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.

Diff:
---
 gcc/cp/semantics.cc                   |  9 ++++++++-
 gcc/testsuite/g++.dg/cpp0x/dr2351-2.C | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 7d46c3c2db9..82f9dd8dd4e 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -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
index 00000000000..deb1718072e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/dr2351-2.C
@@ -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);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-21  7:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21  7:03 [gcc r13-3429] c++: Fix up mangling ICE with void{} [PR106863] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).