Open xmh0511 opened 1 year ago
I think the intent is specifying when are certain defaulted functions, function template specializations, and variable template specializations instantiated in unevaluated operands (see P0859R0).
There should be no requirements in addition to those for instantiation, or implicit definition for defaulted functions.
So, where's the rule in the document that specifies the following code is ill-formed?
consteval int bar (int x) { return x; }
int i = 5;
bar (i); // ill-formed
After all, the following sentence in n4861 expr.const p13 standard is removed now:
An immediate invocation shall be a constant expression.
Note the italics. This is (simply) a definition of "needed for constant evaluation" for later use by [dcl.fct.def.default] and [temp.inst]. That definition has no local purpose in [expr.const].
Regarding the example, we have
"An invocation is an immediate invocation if it is a potentially-evaluated explicit or implicit invocation of an immediate function and is not in an immediate function context"
So, bar(i)
is an immediate invocation. Thus, this function call expression is manifestly constant evaluated (p19.3).
Hm... But we seem to say nowhere that manifestly constant evaluated expressions need to be constant expressions.
Hm... But we seem to say nowhere that manifestly constant evaluated expressions need to be constant expressions.
I cited the intended rule that could cover this issue in https://github.com/cplusplus/CWG/issues/371, however, as specified in that issue, the rule has some issues too.
After all, the following sentence in n4861 expr.const p13 standard is removed now:
An immediate invocation shall be a constant expression.
I think the requirement is moved to [expr.const] p17:
An immediate-escalating expression shall appear only in an immediate-escalating function.
Hm... But we seem to say nowhere that manifestly constant evaluated expressions need to be constant expressions.
I guess we've almost already separately specified when they need to be constant expressions.
After all, the following sentence in n4861 expr.const p13 standard is removed now:
An immediate invocation shall be a constant expression.
I think the requirement is moved to [expr.const] p17:
An immediate-escalating expression shall appear only in an immediate-escalating function.
Full name of submitter (unless configured in github; will be published with the issue): Jim X
[expr.const] p20 says:
So, what requirements do we want to impose on these constructs?
Suggested Resolution
We may want to say:
However, it is not clear what "is needed for constant evaluation" intend to mean. Consider this example:
[expr.const] p20.2 says
fun(a+1)
is potentially constant evaluated, and [expr.const] p20.6 says it is needed for constant evaluation becausefun
is a constexpr function. However, the expression is not required to be constant expression.