Question Details

No question body available.

Tags

c++ language-lawyer

Answers (1)

May 7, 2026 Score: 4 Rep: 5,010 Quality: Low Completeness: 70%

Though p is immutable (as it is a reference), the value it references is not, even though it is initialized by the constant N. In fact, I guess, a temporary non-const int is materialized when instantiating s and referenced by p which extend its lifetime.

Yet, under https://eel.is/c++draft/expr.const#init-8:

An object or reference is potentially usable in constant expressions at point P if it is
...
a non-mutable subobject of any of the above, or
...

Therefore T::p is not usable inside a constant expression and gcc/clang are right to reject the code.