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

Incorrect constructor in return statement #351

Closed
adromanov opened this issue Nov 23, 2020 · 1 comment
Closed

Incorrect constructor in return statement #351

adromanov opened this issue Nov 23, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@adromanov
Copy link

Consider the following code:


struct A {};

struct Test
{
    Test(const A &);
    Test(A &&);
};

std::optional<Test> foo()
{
    A a;
    return a;
}

in return statement constructor from rvalue reference is called (https://gcc.godbolt.org/z/KeWb4e). This is due to https://en.cppreference.com/w/cpp/language/return "Automatic move from local variables and parameters" part. This also could be seen in AST.
However, the output is (for the foo()):

std::optional<Test> foo()
{
  A a = A();
  return std::optional<Test>(a);
}

Here lvalue refeference constructor is called.

@andreasfertig
Copy link
Owner

Hello @adromanov,

thanks for reporting this interesting issue. I think you uncovered a bigger issue with ImplicitCastExprs in general. With your example, I think an ImplicitCastExpr with NoOp and an xvalue needs to be shown. I'm running some tests and try to figure out how to handle it correctly.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label Nov 23, 2020
andreasfertig added a commit that referenced this issue May 20, 2021
Fixed #351: Show xvalue casts making calls to the move-ctor visible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants