[cfe-dev] [PATCH] libc++: help diagnosing the following std::atomic compile error

Stephan Tolksdorf st at quanttec.com
Wed May 22 02:49:08 PDT 2013


On 22.05.13 01:04, Howard Hinnant wrote:
> I recommend filing a bug against clang on this.  I am hesitant to commit the libc++ fix due to David Chisnall's concerns.  If the clang team reassigns the bug to libc++, then I will commit the libc++ solution.
>

In case anyone has missed the previous reference to 
http://llvm.org/bugs/show_bug.cgi?id=16056 and is considering a decision 
on how to proceed, I'd like to describe the consequence of that issue 
for the current _Atomic-based implementation of <atomic>:

If you initialize a static atomic variable with a constant expression 
(e.g. for some kind of lazy initialization scheme), your value is not 
constant initialized as expected but instead is dynamically initialized 
at program startup (because clang currently doesn't treat _Atomic(T) as 
a literal type). This may make your code vulnerable to the infamous 
"static initialization order fiasco", which can result in difficult to 
find bugs.

I'm not sure how important this issue is, but I thought it might be 
useful to summarize it again in the context of this thread, since it's 
probably something that users of <atomic> should be aware of.

- Stephan




More information about the cfe-dev mailing list