https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113976
--- Comment #10 from Patrick Palka <ppalka at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #8) > E.g. > --- gcc/cp/decl.cc.jj 2024-02-15 09:51:34.460065992 +0100 > +++ gcc/cp/decl.cc 2024-02-19 18:20:23.423410659 +0100 > @@ -15263,7 +15263,14 @@ grokdeclarator (const cp_declarator *dec > /* Record constancy and volatility on the DECL itself . There's > no need to do this when processing a template; we'll do this > for the instantiated declaration based on the type of DECL. */ > - if (!processing_template_decl) > + if (!processing_template_decl > + /* Don't do it for instantiated variable templates either, > + cp_apply_type_quals_to_decl should have been called on it > + already and might have have been overridden in cp_finish_decl > + if initializer needs runtime initialization. */ > + && (!VAR_P (decl) > + || DECL_LANG_SPECIFIC (decl) == NULL > + || !DECL_USE_TEMPLATE (decl))) Maybe checking !DECL_TEMPLATE_INSTANTIATED would be better, since that's set only when the specialization's definition is instantiated from instantiate_body as opposed to DECL_USE_TEMPLATE which gets set when the specialization is formed? > cp_apply_type_quals_to_decl (type_quals, decl); > > return decl; > fixes it, but it is just a random shot in the dark. I think we want to > differentiate > between freshly created VAR_DECL from the grokdeclarator vs. existing > VAR_DECL grokdeclarator just looked up.