On 11/2/25 4:13 AM, Nathaniel Shead wrote:
On Sat, Nov 01, 2025 at 09:13:06PM +0300, Jason Merrill wrote:
On 11/1/25 3:37 AM, Nathaniel Shead wrote:
On Thu, Oct 30, 2025 at 07:20:22PM +0200, Jason Merrill wrote:
On 10/28/25 12:06 AM, Nathaniel Shead wrote:
On Mon, Oct 27, 2025 at 05:04:18PM +0200, Jason Merrill wrote:
On 10/26/25 2:40 PM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15?
-- >8 --
The linker error in the PR is caused because when a static is defined
out of the class body, it doesn't yet have a definition and so
read_var_def (which would otherwise have noted it) never gets called.
I don't object to this change, but there's certainly a definition in
inst6_a, why wouldn't we call read_var_def? I imagine it's because we never
write_var_def for some reason?
Right. We've instantiated Type<int> so a declaration exists for
Type<int>::var, but because of this hunk in instantiate_class_template
no definition has been instantiated yet, so DECL_INITIAL is null, and so
has_definition returns false and we never call write_var_def.
Makes sense, but how is that different from a variable template
specialization that we've instantiated the declaration of, but not the
definition, e.g.
template <class T> T v = T();
decltype(v<int>) v2 = 0;
?
In 'instantiate_decl' we have the following hunk
set_instantiating_module (d);
if (variable_template_p (gen_tmpl))
note_vague_linkage_variable (d);
instantiate_body (td, args, d, false);
Yes, but in my example instantiate_decl is never called.
Sorry I wasn't clear: it's called by 'mark_used' in the importing module
at the point we actually need a definition to be available.
For 'v' in your example this would cause it to be added to
pending_statics to ensure it's emitted during c_parse_final_cleanups,
but 'arr' in my doesn't get added so we get the linker errors as no
definition is ever emitted.
The patch is OK.
Jason