Skip to content

Full expression

在阅读cppreference的过程中,在多处碰到了“Full expression”,有必要对这个概念进行总结。

在cppreference Order of evaluation#Rules中枚举了full expression,full expression应该是compile-time概念。

draft

A full-expression is an expression that is not a subexpression of another 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. A call to a destructor generated at the end of the lifetime of an object other than a temporary object is an implicit full-expression. Conversions applied to the result of an expression in order to satisfy the requirements of the language construct in which the expression appears are also considered to be part of the full-expression.

Example:

struct S {
    S(int i): I(i) { }
        int& v() { return I; }
    private:
        int I;
    };

    S s1(1); // full-expression is call of S::S(int)
    S s2 = 2; // full-expression is call of S::S(int)
    void f() {
    if (S(3).v()) // full-expression includes lvalue-to-rvalue and
                  // int to bool conversions, performed before
                  // temporary is deleted at end of full-expression
    { }
}

TODO

stackoverflow C++ full-expression standard wording

stackoverflow C++ 17 full-expression standard definition