]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with [[trivial_abi]] [PR125022]
authorJason Merrill <jason@redhat.com>
Tue, 28 Apr 2026 01:41:05 +0000 (21:41 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 28 Apr 2026 04:30:22 +0000 (00:30 -0400)
We don't mess with cleanups at template parsing time.

PR c++/125022

gcc/cp/ChangeLog:

* decl.cc (store_parm_decls): Only do trivial_abi stuff when
!processing_template_decl.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/attr-trivial_abi7.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi7.C [new file with mode: 0644]

index 6415f0b4bc211402cc278406475961075b6f4f7d..f0f37560dec33b5f9dcdc62a086c45a501269968 100644 (file)
@@ -20271,20 +20271,21 @@ store_parm_decls (tree current_function_parms)
 
   /* Register cleanups for parameters with trivial_abi attribute, the cleanup
      of which is the callee's responsibility.  */
-  for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
-    {
-      if (TREE_CODE (parm) == PARM_DECL)
-       {
-         tree parm_type = TREE_TYPE (parm);
-         if (has_trivial_abi_attribute (parm_type))
-           {
-             tree cleanup
-               = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
-             if (cleanup && cleanup != error_mark_node)
-               finish_decl_cleanup (parm, cleanup);
-           }
-       }
-    }
+  if (!processing_template_decl)
+    for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
+      {
+       if (TREE_CODE (parm) == PARM_DECL)
+         {
+           tree parm_type = TREE_TYPE (parm);
+           if (has_trivial_abi_attribute (parm_type))
+             {
+               tree cleanup
+                 = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
+               if (cleanup && cleanup != error_mark_node)
+                 finish_decl_cleanup (parm, cleanup);
+             }
+         }
+      }
 
   if (use_eh_spec_block (current_function_decl))
     current_eh_spec_block = begin_eh_spec_block ();
diff --git a/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi7.C b/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi7.C
new file mode 100644 (file)
index 0000000..4c76e5e
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/125022
+// { dg-do compile { target c++11 } }
+
+struct raw_ptr {
+  raw_ptr(int *);
+};
+struct [[clang::trivial_abi]] scoped_refptr {
+  ~scoped_refptr();
+  template <typename...> void emplace(scoped_refptr) {}
+} main_thread_, AsyncMemoryConsumerRegistration_main_task_runner;
+struct AsyncMemoryConsumerRegistration {
+  AsyncMemoryConsumerRegistration();
+  raw_ptr consumer_;
+};
+int AsyncMemoryConsumerRegistration_consumer;
+AsyncMemoryConsumerRegistration::AsyncMemoryConsumerRegistration()
+    : consumer_(&AsyncMemoryConsumerRegistration_consumer) {
+  main_thread_.emplace(AsyncMemoryConsumerRegistration_main_task_runner);
+}