[llvm-bugs] [Bug 25640] New: -Wpessimizing-move false positive for return value of statement expression

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 25 12:59:11 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25640

            Bug ID: 25640
           Summary: -Wpessimizing-move false positive for return value of
                    statement expression
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sugak at fb.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following code generates a -Wpessimizing-move violation:
```
#include <memory>
#include <utility>
class C {};
void f() {
  auto c = ({auto c1 = std::make_unique<C>(); std::move(c1);});
}
1.cpp:5:47: error: moving a local object in a return statement prevents copy
elision [-Werror,-Wpessimizing-move]
  auto c = ({auto c1 = std::make_unique<C>(); std::move(c1);});
                                              ^
1.cpp:5:47: note: remove std::move call here
  auto c = ({auto c1 = std::make_unique<C>(); std::move(c1);});
                                              ^~~~~~~~~~  ~
```
When `std::move` is removed, it becomes a syntax error: 
```
1.cpp:5:47: error: call to deleted constructor of 'std::unique_ptr<C,
std::default_delete<C> >'
  auto c = ({auto c1 = std::make_unique<C>(); c1;});
                                              ^~
.../unique_ptr.h:356:7: note: 'unique_ptr' has been explicitly marked deleted
here
      unique_ptr(const unique_ptr&) = delete;
      ^
1 error generated.
```


clang --version
clang version 3.8.0 (trunk 251726)
Target: x86_64-unknown-linux-gnu
Thread model: posix

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151125/3fcc4443/attachment.html>


More information about the llvm-bugs mailing list