[LLVMbugs] [Bug 11979] New: Unclear diagnostic when failed conversion is from implicit temporary inside copy initialization

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Feb 10 20:26:22 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=11979

             Bug #: 11979
           Summary: Unclear diagnostic when failed conversion is from
                    implicit temporary inside copy initialization
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++0x
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following diagnostic misses a step in explaining what actually went wrong.

$ cat test.cc
#include <map>
#include <iostream>
#include <utility>
#include <memory>

struct Base {};
struct Derived : public Base {};
int main() {
  std::unique_ptr<Derived> u(new Derived);
  const std::unique_ptr<Base> u2 = std::move(u);
}
$ clang++ -stdlib=libc++ -std=c++11 test.cc -o test && ./test
test.cc:10:31: error: copying variable of type 'const std::unique_ptr<Base>'
invokes deleted constructor
  const std::unique_ptr<Base> u2 = std::move(u);
                              ^    ~~~~~~~~~~~~

-------------

The initial conversion to "const std::unique_ptr<Base>" succeeded, but then
because unique_ptr is move-only, and it can't move from a _const_ unique_ptr,
the second step failed. The error message should mention that this only failed
because the '=' caused copy-initialization, and probably provide a fixit to use
direct initialization instead.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list