The cppreference page for [[assume]]
says that:
[[assume( expression )]]
[...] the expression is not evaluated (but it is still potentially evaluated).
This wording confuses me. Is cppreference wrong here?
Why would it be potentially evaluated if it's not evaluated? Isn't it an unevaluated operand like the expression in sizeof
?
If not, what are the consequences?
The C++ standard says virtually the same:
- [dcl.attr.assume]
Crucially, the standard says that the expression is not evaluated, however the expression is not an unevaluated operand. The wording is carefully chosen and very important.
- [basic.def.odr]/3
Consequences
As a result
[[assume]]
enjoys none of the privileges that unevaluated operands have. To name one example, we cannot refer to non-static data members directly:It only makes sense that
[[assume]]
is potentially evaluated, because it informs the compiler that a certain runtime expression would evaluate totrue
, if it was evaluated, hypothetically.The expression must be something that the compiler could potentially evaluate, even if it never does.