Skip to content
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

What is "the full-expression of its initialization"? #4798

Open
xmh0511 opened this issue Aug 7, 2021 · 0 comments
Open

What is "the full-expression of its initialization"? #4798

xmh0511 opened this issue Aug 7, 2021 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Aug 7, 2021

The term full-expression is defined in [basic.exec.intro.execution] p5

A full-expression is

  • an unevaluated operand,
  • a constant-expression ([expr.const]),
  • an immediate invocation ([expr.const]),
  • an init-declarator ([dcl.decl]) or a mem-initializer ([class.base.init]), including the constituent expressions of the initializer,
  • an invocation of a destructor generated at the end of the lifetime of an object other than a temporary object ([class.temporary]) whose lifetime has not been extended, or
  • an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression.

None of the above bullets is related to "initialization". In my opinion, It seems the term "initialization" is a sequence of expressions whose invocations would initialize an entity. Although, "initialization" has no formal definition in the standard. Consider this example

struct A{
    constexpr A(int){}
};
struct B{
   constexpr B(A const& v):v_(v){}
   A v_;
};
constexpr B b = A(0);  //#1

According to the definition for full-expression, the full-expression in the declaration at #1 should be its init-declarator(namely, b = A(0)).

The [basic.exec.intro.execution] p5 also says

For an initializer, performing the initialization of the entity (including evaluating default member initializers of an aggregate) is also considered part of the full-expression.

Hence, "the full-expression of its initialization" at #1 refers to the init-declarator? [expr.const] p2 says

the full-expression of its initialization is a constant expression when interpreted as a constant-expression

While the definition for constant expression is defined at [expr.const] p11

A constant expression is either a glvalue core constant expression that refers to an entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value satisfies the following constraints

Anyhow, the constant expression should first be an expression on grammar. A full-expression is a concept that is convenient to name a language structure that is not necessary to be an expression. As aforementioned, the full-expression is an init-declarator, how could it be a constant expression?

The full-expression at #1 comprises the implicitly call of B::B(A const& v), temporary materialization conversion on A(0) and the destruction of that temporary object. I think the intent is saying that these expressions should satisfy the requirement of a constant expression. However, the current wording is obscure to read and a bit contradictory. The same issue https://stackoverflow.com/questions/62253964/what-is-full-expression-of-initialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant