From: Jason Merrill Date: Tue, 28 Apr 2026 01:41:05 +0000 (-0400) Subject: c++: ICE with [[trivial_abi]] [PR125022] X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=fb7d898dbc4d0b1bf099cae8635e205fa8981dc2;p=thirdparty%2Fgcc.git c++: ICE with [[trivial_abi]] [PR125022] 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. --- diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 6415f0b4bc2..f0f37560dec 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -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 index 00000000000..4c76e5e9df3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/attr-trivial_abi7.C @@ -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 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); +}