aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-01-03 09:27:06 +1100
committerNathaniel Shead <nathanieloshead@gmail.com>2024-01-26 22:28:45 +1100
commita0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a (patch)
tree26ae2a56bd68dade9e597ab1508c97dce4fd3380 /gcc/cp
parentf9b143d239db775318a29e9ff63f232b9501a22a (diff)
downloadgcc-a0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a.zip
gcc-a0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a.tar.gz
gcc-a0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a.tar.bz2
c++: Emit definitions of ODR-used static members imported from modules [PR112899]
Static data members marked 'inline' should be emitted in TUs where they are ODR-used. We need to make sure that inlines imported from modules are correctly added to the 'pending_statics' map so that they get emitted if needed, otherwise the attached testcase fails to link. PR c++/112899 gcc/cp/ChangeLog: * cp-tree.h (note_variable_template_instantiation): Rename to... (note_vague_linkage_variable): ...this. * decl2.cc (note_variable_template_instantiation): Rename to... (note_vague_linkage_variable): ...this. * pt.cc (instantiate_decl): Rename usage of above function. * module.cc (trees_in::read_var_def): Remember pending statics that we stream in. gcc/testsuite/ChangeLog: * g++.dg/modules/init-4_a.C: New test. * g++.dg/modules/init-4_b.C: New test. * g++.dg/modules/init-6_a.H: New test. * g++.dg/modules/init-6_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Jason Merrill <jason@redhat.com
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/decl2.cc4
-rw-r--r--gcc/cp/module.cc5
-rw-r--r--gcc/cp/pt.cc2
4 files changed, 9 insertions, 4 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 60e6daf..f46b448 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7151,7 +7151,7 @@ extern tree maybe_get_tls_wrapper_call (tree);
extern void mark_needed (tree);
extern bool decl_needed_p (tree);
extern void note_vague_linkage_fn (tree);
-extern void note_variable_template_instantiation (tree);
+extern void note_vague_linkage_variable (tree);
extern tree build_artificial_parm (tree, tree, tree);
extern bool possibly_inlined_p (tree);
extern int parm_index (tree);
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 91d4e2e..f569d40 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -947,10 +947,10 @@ note_vague_linkage_fn (tree decl)
vec_safe_push (deferred_fns, decl);
}
-/* As above, but for variable template instantiations. */
+/* As above, but for variables. */
void
-note_variable_template_instantiation (tree decl)
+note_vague_linkage_variable (tree decl)
{
vec_safe_push (pending_statics, decl);
}
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index f26b226..6176801b 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11789,6 +11789,11 @@ trees_in::read_var_def (tree decl, tree maybe_template)
DECL_INITIALIZED_P (decl) = true;
if (maybe_dup && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (maybe_dup))
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
+ if (DECL_IMPLICIT_INSTANTIATION (decl)
+ || (DECL_CLASS_SCOPE_P (decl)
+ && !DECL_VTABLE_OR_VTT_P (decl)
+ && !DECL_TEMPLATE_INFO (decl)))
+ note_vague_linkage_variable (decl);
}
DECL_INITIAL (decl) = init;
if (!dyn_init)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 7401353..f5bf159 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27300,7 +27300,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
{
set_instantiating_module (d);
if (variable_template_p (gen_tmpl))
- note_variable_template_instantiation (d);
+ note_vague_linkage_variable (d);
instantiate_body (td, args, d, false);
}