Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Taking the address is odr-use but I'm concerned about potentially permitted optimisations, given that I literally never do anything with the object, despite the side effects of construction and destruction (let's face it, there are examples of exceptions to that in the language) Commented Feb 7, 2018 at 18:49
  • Since the constructor of Bar gets called, there's no way any optimizer will remove that statement. Commented Feb 7, 2018 at 18:50
  • 1
    @WouterHuysentruit: It's a little more complicated than just looking at the declaration and saying the constructor gets called: remove (void)&b and you'll find that it isn't. The guarantee I'm looking for is that adding (void)&b back in ensures that it is. Commented Feb 7, 2018 at 18:51
  • 3
    I asked something similar here. The standard guarantees that a thread-local is initialized before its first odr-use, and &bar is indeed an ODR-use. Am I missing something? Commented Feb 7, 2018 at 18:57
  • I was indeed referring to the (void)&bar statement, which you shouldn't remove of course. Commented Feb 7, 2018 at 18:58