https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83428
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Aliaksei Kandratsenka from comment #3)
> constructor is defined after variable in this example. I am not sure this
> real bug.
Agreed. If we use Clang and add its require_constant_initialization attribute
to the variable definition it tells us:
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.
If the S1::S1() constructor is defined before the definition of objX then Clang
doesn't warn and GCC doesn't use dynamic initialization.