Hi!

The following testcase ICEs during error recovery.  We try to
mangle a structured binding base variable, but because it has
been erroneous, the mangling ICEs as it can't find the corresponding
structured bindings.

Now, we already have a hack in cp_finish_decomp when things are erroneous,
we set assembler name to <decomp> so that mangling isn't done.
But we do that only for DECL_NAMESPACE_SCOPE_P bases and
block scope static structured bindings can be mangled too,
and during instantiation, if tsubst_decomp_names fails, we don't
call cp_finish_decomp at all, so in that case we need to also
avoid the mangling of the structured binding base.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2026-07-02  Jakub Jelinek  <[email protected]>

        PR c++/126057
        * decl.cc (cp_finish_decomp): Set assembler name to
        <decomp> during error recovery whenever TREE_STATIC
        rather than just DECL_NAMESPACE_SCOPE_P.
        * pt.cc (tsubst_stmt): If tsubst_decomp_names fails,
        set assembler name to <decomp>.

        * g++.dg/cpp2a/decomp11.C: New test.

--- gcc/cp/decl.cc.jj   2026-07-01 11:54:35.402958896 +0200
+++ gcc/cp/decl.cc      2026-07-01 19:19:33.763975576 +0200
@@ -10708,7 +10708,7 @@ cp_finish_decomp (tree decl, cp_decomp *
            }
          first = DECL_CHAIN (first);
        }
-      if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
+      if (DECL_P (decl) && TREE_STATIC (decl))
        SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
       return false;
     }
--- gcc/cp/pt.cc.jj     2026-06-25 10:03:50.817436390 +0200
+++ gcc/cp/pt.cc        2026-07-01 19:25:16.135679755 +0200
@@ -19917,7 +19917,14 @@ tsubst_stmt (tree t, tree args, tsubst_f
                        if (tsubst_decomp_names (decl, pattern_decl, args,
                                                 complain, in_decl, decomp)
                            == error_mark_node)
-                         decomp = NULL;
+                         {
+                           decomp = NULL;
+                           if (TREE_STATIC (decl))
+                             {
+                               tree id = get_identifier ("<decomp>");
+                               SET_DECL_ASSEMBLER_NAME (decl, id);
+                             }
+                         }
                      }
 
                    init = tsubst_init (init, decl, args, complain, in_decl);
--- gcc/testsuite/g++.dg/cpp2a/decomp11.C.jj    2026-07-01 19:28:37.892148276 
+0200
+++ gcc/testsuite/g++.dg/cpp2a/decomp11.C       2026-07-01 19:28:18.524391284 
+0200
@@ -0,0 +1,12 @@
+// PR c++/126057
+// { dg-do compile { target c++20 } }
+
+template <typename T>
+int
+foo ()
+{
+  static auto [a] = 0; // { dg-error "cannot decompose non-array non-class 
type 'int'" }
+  return 0;
+}
+
+int a = foo <int> ();

        Jakub

Reply via email to