https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120806
Bug ID: 120806 Summary: std::out_ptr is not conforming to the standard Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: xyb at lotx dot org Target Milestone: --- The following code will output the wrong result when using gcc: ``` #include <memory> #include <print> int f(int** raw) { *raw = new int; return 0; } int main() { std::unique_ptr<int> p; if (f(std::out_ptr(p)) || !p) { std::println("p is empty"); } else { std::println("p is not-empty"); } } ``` `clang++ -std=c++23 -stdlib=libc++` will output "p is empty". `cl /std:c++latest` will output "p is empty". `g++ -std=c++23` will output "p is not empty". In standard, the adapted smart pointer object will be reset with the result when the temporary `std::out_ptr_t` is destroyed. In the above code, when `!p` is evaluated, the temporary object hasn't been destroyed, so the value of `p` is still empty. The output should be "p is empty".