The following code is compiled by gcc with -std=c++17 constexpr bool f() { int const a = 0; const_cast<int &>(a) = 2; return a == 0; } static_assert(f()); This should not be allowed because we modify a const value in a constant expression. Here is another example test case that does not use const_cast (and gives a different answer in the return statement, but I don't think that's especially relevant because it's undefined behavior anyway): struct S { int a = 1; int * ptr = &a; }; constexpr bool f() { auto const s = S{}; *s.ptr = 2; return s.a == 2; } static_assert(f());
This looks like a duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85125
Closing as duplicate *** This bug has been marked as a duplicate of bug 85125 ***