https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86974
Bug ID: 86974 Summary: Support Clang's require_constant_initialization attribute Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- As documented at https://clang.llvm.org/docs/AttributeReference.html#require-constant-initialization-clang-require-constant-initialization This attribute is very useful to check that a global uses constant initialization, thus avoiding the Static Initialization Order Fiasco. For example, see PR 83428 where it was mistakenly believed that the variable should not be dynamically initialized, but actually there was a bug in the code preventing it. If the variable will not get constant initialization Clang gives an error and states the reason for dynamic init: 83428.cc:20:54: error: variable does not have a constant initializer __attribute__((require_constant_initialization)) S2 objX; ^~~~ 83428.cc:20:17: note: required by 'require_constant_initialization' attribute here __attribute__((require_constant_initialization)) S2 objX; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 83428.cc:12:7: note: undefined constructor 'S1' cannot be used in a constant expression : m_tabS1() ^ 83428.cc:20:54: note: in call to 'S2()' __attribute__((require_constant_initialization)) S2 objX; ^ 83428.cc:3:15: note: declared here constexpr S1 (); ^ 1 error generated. So this doesn't change the meaning of any code, it just acts as an assertion that a property is true.