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

Wrong comment in [intro.execution]/12's example #1650

Closed
jabelloc opened this issue Jun 28, 2017 · 6 comments
Closed

Wrong comment in [intro.execution]/12's example #1650

jabelloc opened this issue Jun 28, 2017 · 6 comments

Comments

@jabelloc
Copy link

[intro.execution]/12:

A full-expression is

...

[ Example:

    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)
    void f() {
          S s2 = 2;      // full-expression is call of S::S(int)
          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
          { }
          bool b = noexcept(S());       // exception specification of destructor of S
                                        // considered for noexcept
                                         // full-expression is destruction of s2 at end of block
    }
    struct B {
          B(S = S(0));
    };
    B b[2] = { B(), B() };     // full-expression is the entire initialization
                               // including the destruction of temporaries

end example ]

The comment

// full-expression includes lvalue-to-rvalue and

above, should be replaced by

// full-expression includes the temporary-materialization and

Note that the prvalue S(3) is subjected to a temporary-materialzation convertion to an xvalue. The dot(.) class member operator requires a glvalue as a postfix expression. See [expr.ref]/2.

@cpplearner
Copy link
Contributor

cpplearner commented Jun 29, 2017

AFAIK S(3).v() in isolation is an lvalue of type int. It is then converted to an rvalue, and then converted to bool.

The comment probably does not contain what you expect it to say, but I personally don't think it is factually wrong.

Just my two cents.

@jabelloc
Copy link
Author

It is then converted to an rvalue, and then converted to bool.

This is not correct. There is no lvalue-to-rvalue conversion preceding the int to bool conversion. Nevertheless, the temporary materialization conversion is required for the prvalue postfix expression S(3) at the left of the dot operator. [expr.ref]/2 clearly says that such expression must be a glvalue.

@cpplearner
Copy link
Contributor

cpplearner commented Jun 30, 2017

As far as I know, the standard conversion sequence from "lvalue of type int" to "rvalue of type bool" consists of an lvalue-to-rvalue conversion ([conv.lval]) and a boolean conversion ([conv.bool]). The comment "int to bool conversion" is just a somewhat more detailed description of the latter (the boolean conversion).

@jabelloc
Copy link
Author

You are right. The boolean conversion expects a prvalue and so, an lvalue-to-rvalue conversion is required before that. But again, the temporary materialization conversion is also required because of [expr.ref]/2. Thanks for the feedback.

@zygoloid
Copy link
Member

The comment is correct as written. The point of the example is to demonstrate that certain constructs occur before the temporary is destroyed; saying that the creation of the temporary is one of those things seems unnecessary to me.

@RazvanAM
Copy link

RazvanAM commented Aug 9, 2017

Why does this paragraph state that for this construct: "S s1(1)" "full-expression is call of S::S(int)"? Shouldn't the full expression be the entire construct itself (because it is an init-declarator)? It would make sense if the comment said: "full-expression contains call of S::S(int)". Am I not understanding something correctly?

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

4 participants