constexpr int f(int const& x) {return x;} constexpr struct S { int x = 0; constexpr S() {(void)f(x); x = 1;} } s; static_assert(f(s.x) == 1, ""); --- Presumably s.x is taken to be "immutable" because s is constexpr, while that's obviously not true during the period of construction.
Confirmed with today's top of trunk: $ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C constexpr int f(int const& x) {return x;} constexpr struct S { int x = 0; constexpr S() {(void)f(x); x = 1;} } s; static_assert(f(s.x) == 1, ""); t.C:8:1: error: static assertion failed static_assert(f(s.x) == 1, ""); ^~~~~~~~~~~~~
Fixed by r255788. Probably it's worth to add the new test.
Author: mpolacek Date: Thu Aug 8 17:54:58 2019 New Revision: 274214 URL: https://gcc.gnu.org/viewcvs?rev=274214&root=gcc&view=rev Log: PR c++/79520 * g++.dg/cpp1y/constexpr-79520.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-79520.C Modified: trunk/gcc/testsuite/ChangeLog
Done.