C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fix bad thread_local codegen (using an attribute?)

From: Levo D <levoplusplusio_at_[hidden]>
Date: Fri, 23 Jan 2026 00:18:26 +0000
On Thu, Jan 22, 2026 at 08:52:01AM +0000, Jonathan Wakely wrote:
> On Thu, 22 Jan 2026, 05:05 Levo D via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
> > > ...
> > > Discussion over?
> >
> > Actually, yes, maybe. I may have to change the problem because my real
> > code is more complex.
> > Your inline suggestion on a variable appears to work on my test. I don't
> > believe I ever seen inline being used with a variable before.
> >
>
> It's been part of the C++ standard since C++17.

Quick update. Thiago inline suggestion 'works', but only for simple types.
The gcc and clang optimizer doesn't want to play nice. Playing around, I notice adding a non-constexpr constructor
will have the optimizer call an initalizer even though it sees how I initalize the variable.

I’m not sure what to do besides keeping my __thread code and ugly workaround.
Maybe I’ll file a bug report. Not sure if I want to bother when it’s about the optimizer.
The workaround is only slightly ugly and optimizes very well

Received on 2026-01-23 00:18:29