New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dcl.constexpr] A full-expression of initialization of a variable may be not an expression #4852
Comments
Actually, the concern in #4798 arises from certain examples struct T{
constexpr T(Class const& rf){} // #1
};
constexpr T const& rf = T{Class()}; In this full-expression of the initialization, it will comprise the call of The purpose of "when interpreted as constant-expression" is that we give a hypothetical grammar meaning to "full-expression of the initialization" that should have been not an expression on grammar, in order to make all semantic rules that apply to the expression on grammar apply to "full-expression of the initialization". “full-expression ” works for collecting these separated expressions. We lack the wording about the storage duration of the temporary variable in this full-expression of initialization, as specified in #4840. |
BTW, since @jensmaurer in #4837 has answered like this
the full-expression of the initialization is the exception, I try to adjust the example above that comment as the following struct A{
constexpr A() = default;
constexpr A(int){}
};
constexpr A t = A(0); //#1 The specifier constexpr in the variable declaration requires that the full-expression of the initialization is a constant expression, even though it is not a syntactical expression, and we impose it to interpret as a constant-expression that is syntactical, however, what's the value category of this hypothetical constant-expression? It seems to lack to expound. I think the value category is significant here since a constant expression is either a glvalue or prvalue core constant expression, we require to do further checks according to their value category. |
Proposed changes: Change [dcl.constexpr] p10:
to
Change [expr.const] p2 (2.2):
to
@xmh0511 @jensmaurer How do you think about these changes? Is a CWG issue needed? Add following contents to show how to transform the constraints:
|
Oh, initialization of an object that is neither variable nor temporary object can also satisfy these constraints, and such initialization can appear in constant evaluation since C++20. |
I would say "full-expression of its initialization" is not an expression of the grammar, whether a construct is a core constant expression or not is first based on it is an expression of the grammar.
IMO, change the following normative rule
to be a note may be radical but it seems plausible. I think for any initialization of an object, the destructor call cannot appear in that full-expression, even though the object is temporary whose lifetime has been extended or not. |
I think the updated wording can show how to transform the constraints of a core constant expression. |
After thinking more about this issue. I think the point of clarifying this issue is:
Consider a slightly complex example: struct A{
constexpr A(int){}
};
constexpr A&& rf = 0; // #1 First, what is the full-expression of the initialization at
And [dcl.init.ref#5.4.1]
It seems that the language construct init-declarator can be considered as an expression for purposes of the definition of a full-expression. Name the language construct(init-declarator) as the expression
According to [dcl.init.ref#5.3]
The temporary conversion is a part of the full-expression. Also, according to [expr.const] p2.2
we can conclude that: It is my interpretation of full-expression of initialization. |
Originally posted by @xmh0511 in #4837 (comment) and #4798.
Currently [dcl.constexpr] p10 says that in the defintion of a
constexpr
variable, the "full-expression of the initialization" shall be a constant expression. And according to [expr.const] p1, a constant expression is also an expression.However, the "full-expression of the initialization" of a variable may be not an expression. It seems that "full-expression of the initialization" of a variable corresponds to the case specified in [intro.execution] p5 (5.4): an init-declarator (or a mem-initializer) is not an expression.
Note that [expr.const] p2 (2.2) uses "when interpretd as", which may imply that the "full-expression of its initialization" is not itself an expression.
Perhaps there are some contradictions currently, and we should clarify that
The text was updated successfully, but these errors were encountered: