On Sat, Nov 15, 2025 at 10:32:00AM +0530, Jason Merrill wrote:
> On 11/15/25 9:47 AM, Nathaniel Shead wrote:
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk and 15?
> > 
> > -- >8 --
> > 
> > r16-4930-gfd5c057c2d01 ensured that we noted all class-scope variables.
> > But I also added a clause to 'read_var_def' to skip all class-scope
> > instantiations, under the mistaken belief that this would be handled in
> > read_class_def.
> > 
> > But as the testcase shows, read_class_def cannot (and should not)
> > register instantiations of member variable templates, as when reading
> > the class it just sees the template declaration.  So this patch removes
> > the constraint from read_var_def.
> > 
> > This may cause us to note some variables more than once but I think
> > that's unlikely to be a large problem, and adding more constraints may
> > hit another case that I'm not thinking of.
> 
> OK, but I wonder if checking primary_template_specialization_p would help
> avoid the extras?

Thanks.  The following patch instead of the above does seem to work and
avoid these issues:

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index ccabd640757..2b3a9301b6c 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -13062,8 +13062,10 @@ trees_in::read_var_def (tree decl, tree maybe_template)
           if (DECL_EXPLICIT_INSTANTIATION (decl)
               && !DECL_EXTERNAL (decl))
             setup_explicit_instantiation_definition_linkage (decl);
-          /* Class static data members are handled in read_class_def.  */
-          if (!DECL_CLASS_SCOPE_P (decl)
+          /* Class non-template static members are handled in read_class_def.
+             But still handle specialisations of member templates.  */
+          if ((!DECL_CLASS_SCOPE_P (decl)
+               || primary_template_specialization_p (decl))
               && (DECL_IMPLICIT_INSTANTIATION (decl)
                   || (DECL_EXPLICIT_INSTANTIATION (decl)
                       && !DECL_EXTERNAL (decl))))

I might submit the first patch for trunk and 15 now though, and will do
some more thorough testing of this (e.g. partial specs) later just for
16, if that's OK.

Nathaniel

Reply via email to