From abdf0b6cdff5783b97f35ad61ae31433f0569dfd Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 27 Jun 2023 05:15:01 -0400 Subject: c++: inherited constructor attributes Inherited constructors are like constructor clones; they don't exist from the language perspective, so they should copy the attributes in the same way. But it doesn't make sense to copy alias or ifunc attributes in either case. Unlike handle_copy_attribute, we do want to copy inlining attributes. The discussion of PR110334 pointed out that we weren't copying the always_inline attribute, leading to poor inlining choices. PR c++/110334 gcc/cp/ChangeLog: * cp-tree.h (clone_attrs): Declare. * method.cc (implicitly_declare_fn): Use it for inherited constructor. * optimize.cc (clone_attrs): New. (maybe_clone_body): Use it. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/nodiscard-inh1.C: New test. --- gcc/cp/method.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/cp/method.cc') diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 91cf943..8ed967d 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -3294,6 +3294,8 @@ implicitly_declare_fn (special_function_kind kind, tree type, /* Copy constexpr from the inherited constructor even if the inheriting constructor doesn't satisfy the requirements. */ constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor); + /* Also copy any attributes. */ + DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor)); } /* Add the "this" parameter. */ -- cgit v1.1