[llvm-bugs] [Bug 31461] New: Missing diagnostic for return of std::unique_ptr<Derived> in C++11

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 23 11:21:04 PST 2016


            Bug ID: 31461
           Summary: Missing diagnostic for return of
                    std::unique_ptr<Derived> in C++11
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vmpstr at chromium.org
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Consider the following

#include <memory>

struct A {};
struct B : public A {};

std::unique_ptr<A> f() {
  auto result = std::unique_ptr<B>(new B);
  return result;

In C++11, the return line has to have an std::move, since the type of |result|
doesn't match the return type of the function.

However, it compiles with current clang++

$ clang++ -std=c++11 -c test.cpp
test.cpp:8:10: error: no viable conversion from 'unique_ptr<struct B,
default_delete<struct B>>' to 'unique_ptr<struct A, default_delete<struct A>>'
  return result;
$ clang++ --version
clang version 3.9.0 (trunk 273760)

$ clang++ -std=c++11 -c test.cpp
$ clang++ --version
clang version 3.9.0 (trunk 274367)

Since C++14 does allow this to compile, I suspect that
http://reviews.llvm.org/D21619 inadvertently caused this.

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/20161223/57ab7216/attachment.html>

More information about the llvm-bugs mailing list