Bug 66109 - defining constexpr objects without initializer
Summary: defining constexpr objects without initializer
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2015-05-11 16:36 UTC by Vlad Gheorghiu
Modified: 2022-11-09 19:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vlad Gheorghiu 2015-05-11 16:36:02 UTC
The following code 

struct Foo
{
    constexpr Foo() = default;
};

int main()
{
    constexpr Foo foo;  
}


should not compile. Unfortunately it compiles with all g++ versions (that support c++11) up to and including 5.1 

From [decl.constexpr]:

A constexpr specifier used in an object declaration declares the object as const. Such an object shall have literal type and shall be initialized.

Therefore the correct way of usage should be

    constexpr Foo foo{};
Comment 1 Vlad Gheorghiu 2015-05-11 16:37:30 UTC
Actually the `constexpr` ctor is not even necessary here to reproduce the bug.
Comment 2 Vlad Gheorghiu 2015-05-11 16:58:01 UTC
More details at http://stackoverflow.com/q/30172483/3093378