This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/83428] Static initialization and struct with constexpr ctor
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 16 Aug 2018 08:00:17 +0000
- Subject: [Bug c++/83428] Static initialization and struct with constexpr ctor
- Auto-submitted: auto-generated
- References: <bug-83428-4@http.gcc.gnu.org/bugzilla/>
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.