]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: reference to static local meta::info as targ [PR124824]
authorPatrick Palka <ppalka@redhat.com>
Tue, 14 Apr 2026 19:36:54 +0000 (15:36 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 15 Apr 2026 16:20:57 +0000 (12:20 -0400)
Here we're crashing in discriminator_for_local_entity during mangling
of f<&M>() because determine_local_discriminator is never called for
the static local meta::info M.  The relevant code path in cp_finish_decl
was disabled for consteval-only types in the main Reflection commit
r16-6808 to avoid creating a varpool_node for such types.

This patch naively fixes this by moving the consteval_only_p check so
that we still call determine_local_discriminator for such types.

PR c++/124824

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Sink !consteval_only_p check to
only guard the varpool_node::get_create call.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/mangle6.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl.cc
gcc/testsuite/g++.dg/reflect/mangle6.C [new file with mode: 0644]

index ecdefe300d53a1ff77f0997e4867be79db4bc214..7e40226d739186fe48d59f49371c6bfc395d3041 100644 (file)
@@ -9885,8 +9885,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
         variable.  */
       if (DECL_FUNCTION_SCOPE_P (decl)
          && TREE_STATIC (decl)
-         && !DECL_ARTIFICIAL (decl)
-         && !consteval_only_p (decl))
+         && !DECL_ARTIFICIAL (decl))
        {
          /* The variable holding an anonymous union will have had its
             discriminator set in finish_anon_union, after which it's
@@ -9904,9 +9903,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
              walk_tree (&init, notice_forced_label_r, NULL, NULL);
              add_local_decl (cfun, decl);
            }
-         /* And make sure it's in the symbol table for
-            c_parse_final_cleanups to find.  */
-         varpool_node::get_create (decl);
+         if (!consteval_only_p (decl))
+           /* And make sure it's in the symbol table for
+              c_parse_final_cleanups to find.  */
+           varpool_node::get_create (decl);
        }
 
       if (flag_openmp
diff --git a/gcc/testsuite/g++.dg/reflect/mangle6.C b/gcc/testsuite/g++.dg/reflect/mangle6.C
new file mode 100644 (file)
index 0000000..23030f7
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/124824
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+template<auto V> void f() { }
+
+int main() {
+  {
+    static constexpr auto M = ^^int;
+    f<&M>();
+  }
+  {
+    static constexpr auto M = ^^int;
+    f<&M>();
+  }
+}
+
+// { dg-final { scan-assembler "_Z1fITnDaXadL_ZZ4mainE1MEEEvv" } }
+// { dg-final { scan-assembler "_Z1fITnDaXadL_ZZ4mainE1M_0EEEvv" } }