On Fri, Mar 15, 2024 at 12:12:49PM -0400, Patrick Palka wrote: > On Fri, 15 Mar 2024, Marek Polacek wrote: > > > On Fri, Mar 15, 2024 at 10:35:07AM -0400, Patrick Palka wrote: > > > On Tue, 5 Mar 2024, Marek Polacek wrote: > > > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > > > > > -- >8 -- > > > > Here we ICE because we call register_local_specialization while > > > > local_specializations is null, so > > > > > > > > local_specializations->put (); > > > > > > > > crashes on null this. It's null since maybe_instantiate_noexcept calls > > > > push_to_top_level which creates a new scope. Normally, I would have > > > > guessed that we need a new local_specialization_stack. But here we're > > > > dealing with an operand of a noexcept, which is an unevaluated operand, > > > > and those aren't registered in the hash map. maybe_instantiate_noexcept > > > > wasn't signalling that it's substituting an unevaluated operand though. > > > > > > It thought it was noexcept-exprs rather than noexcept-specs that are > > > unevaluated contexts? > > > > Yes, sigh. It would have to be noexcept(noexcept(x)). I was looking at > > cp_parser_unary_expression/RID_NOEXCEPT but that's a noexcept-expr. So > > what can we do here, set a new local_specialization_stack? That wasn't > > that straightforward when I tried. Or maybe just > > Maybe we can avoid doing push_to_top_level (which clears > local_specializations) from maybe_instantiate_noexcept if > current_function_decl == fn?
Thanks, I agree that not doing push_to_top_level in the first place is a better fix. I just sent a patch that does that. > Relatedly I wonder if we can avoid calling regenerate_decl_from_template > for local class member functions since they can't be redeclared? Good point. I've tried the below, but that breaks a lot of contracts tests. I have not pursued it further than that. diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index a7ba8b5af92..5352453a5d3 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26623,6 +26623,12 @@ regenerate_decl_from_template (tree decl, tree tmpl, tree args) if (DECL_UNIQUE_FRIEND_P (decl)) goto done; + /* [class.mem.general]/5 says that a member shall not be declared twice + in the member-specification (unless it's a nested class or member class + template or an enumeration). */ + if (DECL_CLASS_SCOPE_P (decl)) + goto done; + /* Use the source location of the definition. */ DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (tmpl); Marek