C++ 17 full-expression standard definition

流过昼夜 提交于 2019-12-10 23:32:00

问题


This paragraph from the C++ 17 standard draft states, among others, that:

A full-expression is:

-an unevaluated operand,

-a constant-expression ([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, or

-an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression.

If a language construct is defined to produce an implicit call of a function, a use of the language construct is considered to be an expression for the purposes of this definition. [...]

struct S {

   S(int i): I(i) { }       // full-expression is initialization of I

   int& v() { return I; }
   ~S() noexcept(false) { }
private:
   int I;
};

S s1(1);                   // **full-expression is call of S​::​S(int)**

For the rest of this post I will refer to a "language construct defined to produce an implicit call of a function" simply as "construct".

I have several questions related to the quoted paragraph:

  1. Why is this passage ("and that is not otherwise part of a full-expression") mentioned? The only reasons I can think of are: a "construct" containing an expression (true expression, not the definition used in this paragraph, which considers "constructs" as expressions) that, otherwise, would be regarded as a full-expression or a "construct" containing another "construct", which, similarly, on its own would be considered as a full-expression. Are these reasons correct? If so, I would appreciate some concrete examples.

  2. What are some examples of "constructs"? I know that the initialization of an object could be one (because of the implicit call to the constructor), but the third dot of the paragraph ("an init-declarator ([dcl.decl])) explicitly considers it as a full-expression. Also, using the new operator means implicitly calling two functions (one for allocating the space and afterwards the constructor), but a new expression is an expression on its own.

  3. Why for the construct: "S s1(1)" is it said that the full-expression is the call to the constructor "S::S(int)"? Why isn't the full-expression the construct itself?

来源:https://stackoverflow.com/questions/45576309/c-17-full-expression-standard-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!