https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81852
Bug ID: 81852 Summary: Feature request: __cpp_threadsafe_static_init Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: daniel.kruegler at googlemail dot com Target Milestone: --- Since the recent update of "Feature-testing recommendations for C++", http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0096r4.html#recs.cpp11 the feature macro "__cpp_threadsafe_static_init" has been recommended for C++ language level c++11 on. This is extremely useful to have for code that has to program defensively against the possibility that thread-safe static locale initialization has been deactivated (via -fno-threadsafe-statics). With that feature macro available, portable code can be written that always provides a thread-safe static initialization, for example by means of std::call_once as the following excerpt demonstrates: Thingy& get_thing() { #ifndef __cpp_threadsafe_static_init [...] static std::once_flag flag; std::call_once(flag, init::get); return init::get(); #else static Thingy result; return result; #endif } Current clang HEAD 6.0.0 (https://github.com/llvm-mirror/clang.git 43) has already provided support for this. A test-case would be that given the compiler flags $ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic the following would be well-formed: //<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #ifndef __cpp_threadsafe_static_init # error "__cpp_threadsafe_static_init not defined" #endif int main() { } //<<<<<<<<<<<<<<<<<<<<<<<<<<<<< while given the compiler flags $ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic "-fno-threadsafe-statics" the same code should be ill-formed: prog.cc:2:3: error: #error "__cpp_threadsafe_static_init not defined" # error "__cpp_threadsafe_static_init not defined" ^~~~~