Bug 71391 - error on aggregate initialization with side-effects in a constexpr function
Summary: error on aggregate initialization with side-effects in a constexpr function
Status: RESOLVED DUPLICATE of bug 66450
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2016-06-02 17:21 UTC by Martin Sebor
Modified: 2017-02-16 00:27 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2016-06-02 17:21:37 UTC
All versions of GCC reject the following valid C++ 14 program.  (Clang and EDG accept it as expected.)

$ cat zzz.cpp && /home/msebor/build/gcc-6-branch/gcc/xgcc -B /home/msebor/build/gcc-6-branch/gcc -S -Wall -Wextra -Wpedantic zzz.cpp 
struct S { int a, b; };

constexpr S f ()
{
  int x = 0;
  S z = { 0, ++x }; 
  return z;
}

constexpr S s = f ();

static_assert (s.a + 1 == s.b, "");
zzz.cpp:12:1: error: non-constant condition for static assertion
 static_assert (s.a + 1 == s.b, "");
 ^~~~~~~~~~~~~
zzz.cpp:12:1: error: the value of ‘s’ is not usable in a constant expression
zzz.cpp:10:13: note: ‘s’ used in its own initializer
 constexpr S s = f ();
             ^
Comment 1 Martin Sebor 2017-02-16 00:27:13 UTC
This appears to have been fixed in r224381 (gcc 6.0.0):

r224381 | jason | 2015-06-11 11:45:01 -0400 (Thu, 11 Jun 2015) | 3 lines

	PR c++/66450
	* constexpr.c (cxx_eval_store_expression): Avoid messing up outer
	ctx->ctor.

*** This bug has been marked as a duplicate of bug 66450 ***