The following C++11 program:
int x = 42;
void f()
{
int y = 43;
static_assert(&x < &y, "foo");
}
int main()
{
f();
Yes, you're missing the fact that, while y
itself is initialised with a constant expression, that's not the same as &y
.
The address of y
can vary a great deal depending on your call stack history.
Paragraph 3 of C++11 5.19 Constant expressions
states the conditions under which the address-of operator can be considered a constant expression (how core constant expressions detailed in paragraph 2 are allowed to morph into "real" constant expressions):
... An address constant expression is a prvalue core constant expression of pointer type that evaluates to the address of an object with static storage duration, to the address of a function, or to a null pointer value, or a prvalue core constant expression of type std::nullptr_t. Collectively, literal constant expressions, reference constant expressions, and address constant expressions are called constant expressions.
Since &y
is none of those things, it's not considered a constant expression.