[expr.const] Clarify example on when evaluation takes place #6853
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I believe that [expr.const] Example 8 is at best unclear, and at worst misleading in its current form:
Firstly, I think "must" is pretty strong language for an example. Don't we have style guides against "must" and "may" in examples?
Secondly, the initialization of an array
array
doesn't take place during translation. The "during translation" clearly refers to the constant-expression in the array size, not to the entire statement.Thirdly, there is no such thing as "runtime" in C++. In a C++ sense, the second line has to be evaluated during program execution, and I don't believe that the compiler is free to manifestly constant-evaluate the initializer of
size
as it pleases here. However, evaluation during program execution may actually take place during compilation, according to the "as-if rule". In short:int size = ...
is evaluated during program executionMixing standardese terms like "during translation" with "at runtime" in two consecutive lines is simply confusing.
It's also worth noting that Note 10 (right above) uses the terminology "during program execution" already; so it makes sense for the example to use this terminology as well.