public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66450] New: [5 Regression][C++11][constexpr] Issues when delegating implicit copy constructor in constexpr function
@ 2015-06-07 15:31 mosra at centrum dot cz
  2015-06-08 17:48 ` [Bug c++/66450] " daniel.kruegler at googlemail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mosra at centrum dot cz @ 2015-06-07 15:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450

            Bug ID: 66450
           Summary: [5 Regression][C++11][constexpr] Issues when
                    delegating implicit copy constructor in constexpr
                    function
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mosra at centrum dot cz
  Target Milestone: ---

The following code is compiled fine in both GCC 4.9.2 and Clang 3.6:

    struct foo {
        constexpr foo(int a);

        constexpr foo(int a, int b, int c): a{a}, b{b}, c{c} {}

        int a, b, c;
    };

    constexpr foo make_foo(int a) { return foo{a, a+1, a+2}; }

    constexpr foo::foo(int a): foo{make_foo(a)} {}

    int main() {
        constexpr const foo f{3};
        static_assert(f.a == 3, "");
        static_assert(f.b == 4, "");
        static_assert(f.c == 5, "");
    }

In GCC 5.1 it produces an error about non-constant condition for static
assertion. If the relevant lines are changed to runtime assert (and #include
<cassert> added):

        assert(f.a == 3);
        assert(f.b == 4);
        assert(f.c == 5);

Then all three assertions fail at runtime, because the copy constructor is
somehow not called and the structure is instead just zeroed out. HOWEVER, if
you remove all occurrences of the constexpr keyword, the code compiles, no
runtime assertion is fired and everything behaves as expected.

The behavior is the same for -std=c++11 and -std=c++14.

I think the static assertion error and the zero-initialization are somehow
related, so I put these into single issue instead of creating two separate
ones.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-23 15:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-07 15:31 [Bug c++/66450] New: [5 Regression][C++11][constexpr] Issues when delegating implicit copy constructor in constexpr function mosra at centrum dot cz
2015-06-08 17:48 ` [Bug c++/66450] " daniel.kruegler at googlemail dot com
2015-06-11 15:45 ` jason at gcc dot gnu.org
2015-06-17 14:33 ` jason at gcc dot gnu.org
2015-06-23 15:30 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).