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

[stmt.return] p5 "which" is ambiguous in the sentence #6616

Closed
xmh0511 opened this issue Oct 11, 2023 · 1 comment
Closed

[stmt.return] p5 "which" is ambiguous in the sentence #6616

xmh0511 opened this issue Oct 11, 2023 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Oct 11, 2023

[stmt.return] p5 says:

The copy-initialization of the result of the call is sequenced before the destruction of temporaries at the end of the full-expression established by the operand of the return statement, which, in turn, is sequenced before the destruction of local variables ([stmt.jump]) of the block enclosing the return statement.

What does the which in the sentence refer to? It can be read as

  1. "which" refers to "The copy-initialization of the result of the call"
  2. "which" refers to "the destruction of temporaries"

According to this example:

#include <iostream>
struct Drop{
    Drop(int id):id_(id){

    }
    int id_;
    ~Drop(){
        std::cout<<"drop "<< id_<<std::endl;
    }
};
int g(){
    Drop x{0};
    {
        Drop y{1};
        return ((Drop&&)Drop{2},0);
    }
    return 1;
}
int main(){ 
   auto c = g();
   std::cout<<"main\n";
}

The outputs are consistent in major implementations, which is

drop 2
drop 1
drop 0
main

It seems that which wants to refer to "the destruction of temporaries"

Suggested Resolution

The copy-initialization of the result of the call is sequenced before the destruction of temporaries at the end of the full-expression established by the operand of the return statement, and the destruction of the temporaries is sequenced before the destruction of local variables ([stmt.jump]) of the block enclosing the return statement.

@t3nsor
Copy link
Contributor

t3nsor commented Oct 17, 2023

It's not ambiguous at all. "A x B, which in turn x C" always means "A x B and B x C", not "A x B and A x C".

@jensmaurer jensmaurer closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
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

3 participants