GCC 11.2 accepts the following example: struct S { static constexpr int C = 5; }; void f() { S s0{}, s1{}; S* a[] = {&s0, &s1}; for (int i = 0; i < 2; ++i) { constexpr int x = S::C; constexpr int y = s0.C; constexpr int z = a[i]->C; } } According to http://eel.is/c++draft/class.static#general-1, the object expression of s0.C and a[i]->C are evaluated, but for example, a[i] is not a constant expression. I think GCC is incorrectly accepting this code. Clang produces the following error: <source>:10:23: error: constexpr variable 'z' must be initialized by a constant expression constexpr int z = a[i]->C; ^ ~~~~~~~ <source>:10:29: note: read of non-const variable 'i' is not allowed in a constant expression constexpr int z = a[i]->C; ^ <source>:7:14: note: declared here for (int i = 0; i < 2; ++i) { ^
ICC and MSVC both accept it like GCC ....
> ICC and MSVC both accept it like GCC .... That's correct, please feel free to report the bug to them as well.
> constexpr int y = s0.C; The above is now valid due to https://wg21.link/p2280r2 (which was acecpted as a defect report against all C++ versions). >constexpr int z = a[i]->C; I think this is invalid still because it is a pointer (not a this pointer) and not a reference.
(In reply to Andrew Pinski from comment #3) > > constexpr int y = s0.C; > > > The above is now valid due to https://wg21.link/p2280r2 (which was acecpted > as a defect report against all C++ versions). Note the paper in the end is https://wg21.link/p2280 .
So confirmed for the pointer case since that is still invalid.