TREE_PUBLIC (fn) = TREE_PUBLIC (var);
DECL_ARTIFICIAL (fn) = true;
DECL_IGNORED_P (fn) = 1;
+ DECL_CONTEXT (fn) = DECL_CONTEXT (var);
/* The wrapper is inline and emitted everywhere var is used. */
DECL_DECLARED_INLINE_P (fn) = true;
if (TREE_PUBLIC (var))
#pragma interface, etc.) we decided not to emit the
definition here. */
&& !DECL_INITIAL (decl)
- /* A defaulted fn in a header module can be synthesized on
- demand later. (In non-header modules we should have
- synthesized it above.) */
- && !(DECL_DEFAULTED_FN (decl) && header_module_p ())
+ /* A defaulted fn or TLS wrapper in a header module can be
+ synthesized on demand later. (In non-header modules we
+ should have synthesized it above.) */
+ && !(header_module_p ()
+ && (DECL_DEFAULTED_FN (decl) || decl_tls_wrapper_p (decl)))
/* Don't complain if the template was defined. */
&& !(DECL_TEMPLATE_INSTANTIATION (decl)
&& DECL_INITIAL (DECL_TEMPLATE_RESULT
if (streaming_p ())
wi (lang->u.fn.u5.fixed_offset);
}
+ else if (decl_tls_wrapper_p (t))
+ /* The wrapped variable. */
+ WT (lang->u.fn.befriending_classes);
else
WT (lang->u.fn.u5.cloned_function);
RT (lang->u.fn.befriending_classes);
lang->u.fn.u5.fixed_offset = wi ();
}
+ else if (decl_tls_wrapper_p (t))
+ RT (lang->u.fn.befriending_classes);
else
RT (lang->u.fn.u5.cloned_function);
decl, cloned_p ? "" : "not ");
}
+ if (streaming_p () && VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
+ u (decl_tls_model (decl));
+
if (streaming_p ())
dump (dumper::TREE) && dump ("Written decl:%d %C:%N", tag,
TREE_CODE (decl), decl);
look like templates. */
if (!install_implicit_member (inner))
set_overrun ();
+
+ /* When importing a TLS wrapper from a header unit, we haven't
+ actually emitted its definition yet. Remember it so we can
+ do this later. */
+ if (state->is_header ()
+ && decl_tls_wrapper_p (decl))
+ note_vague_linkage_fn (decl);
}
else
{
}
}
+ if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
+ {
+ enum tls_model model = tls_model (u ());
+ if (is_new)
+ set_decl_tls_model (decl, model);
+ }
+
if (!NAMESPACE_SCOPE_P (inner)
&& ((TREE_CODE (inner) == TYPE_DECL
&& !is_typedef
--- /dev/null
+// PR c++/113292
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+struct test {
+ static const test& get_instance() {
+ return instance;
+ }
+ static thread_local test instance;
+};
+
+
+template <typename T>
+struct test_template {
+ static const test_template& get_instance() {
+ return instance;
+ }
+ static thread_local test_template instance;
+
+ template <typename U>
+ static const test_template& get_template_instance() {
+ return template_instance<U>;
+ }
+
+ template <typename U>
+ static thread_local test_template template_instance;
+};
+
+template <typename T>
+thread_local test_template<T> test_template<T>::instance;
+
+template <typename T>
+template <typename U>
+thread_local test_template<T> test_template<T>::template_instance;
--- /dev/null
+// PR c++/113292
+// { dg-additional-options "-fmodules-ts" }
+
+import "pr113292_a.H";
+
+// provide a definition of 'instance' so things link
+thread_local test test::instance;
+
+void instantiate() {
+ auto& instance = test::get_instance();
+ auto& t_instance = test_template<int>::get_instance();
+ auto& tt_instance = test_template<int>::get_template_instance<double>();
+};
--- /dev/null
+// PR c++/113292
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts" }
+
+import "pr113292_a.H";
+
+int main() {
+ auto& instance = test::get_instance();
+ auto& t_instance = test_template<int>::get_instance();
+ auto& tt_instance = test_template<int>::get_template_instance<double>();
+}