Issue 56058
Summary [C++] Mandatory copy elision with temporary lifetime extension with incorrect behavior
Labels
Assignees
Reporter joaovitor72
    Suppose the following C++ code:

```
#include <iostream>

struct K
{
    K() { std::cout << "K::K()" << std::endl; }
    K(K const&) { std::cout << "K::K(K const&)" << std::endl; }
    K(K&&) { std::cout << "K::K(K&&)" << std::endl; }
    ~K() { std::cout << "K::~K()" << std::endl; }
};

struct B
{
    K const& l;
    ~B() { std::cout << "B::~B()" << std::endl; }
};

int main() {
    B b = B{ K{} };
    std::cout << "end of main" << std::endl;
    (void)b;
}
```
Under post-C++17 copy elision rule changes the temporary `K{}` should get its lifetime extended to match `B b` lifetime, this is not what currently happens.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to