https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
When looking at GIMPLE dump on:
struct S { S (); ~S (); int i; };
thread_local S s;
struct T { static thread_local S u; } t;
thread_local S T::u;
S *f1 () { return &s; }
int *f2 () { return &s.i; }
S *f3 () { return &t.u; }
int *f4 () { return &t.u.i; }
S *f5 () { return &T::u; }
int *f6 () { return &T::u.i; }
template <int N>
S *f7 () { return &s; }
template <int N>
int *f8 () { return &s.i; }
template <int N>
S *f9 () { return &t.u; }
template <int N>
int *f10 () { return &t.u.i; }
template <int N>
S *f11 () { return &T::u; }
template <int N>
int *f12 () { return &T::u.i; }
void foo ()
{
f7<0> ();
f8<0> ();
f9<0> ();
f10<0> ();
f11<0> ();
f12<0> ();
}
the following patch fixes all but f12:
--- gcc/cp/typeck.c.jj 2019-03-13 21:21:27.000000000 +0100
+++ gcc/cp/typeck.c 2019-03-15 16:23:27.582046214 +0100
@@ -2443,6 +2443,16 @@ build_class_member_access_expr (cp_expr
/* A static data member. */
result = member;
mark_exp_read (object);
+
+ tree wrap;
+ if (!cp_unevaluated_operand
+ && !processing_template_decl
+ && CP_DECL_THREAD_LOCAL_P (result)
+ && (wrap = get_tls_wrapper_fn (result)))
+ /* Replace an evaluated use of the thread_local variable with
+ a call to its wrapper. */
+ result = build_cxx_call (wrap, 0, NULL, tf_warning_or_error);
+
/* If OBJECT has side-effects, they are supposed to occur. */
if (TREE_SIDE_EFFECTS (object))
result = build2 (COMPOUND_EXPR, TREE_TYPE (result), object, result);