Skip to content

Regression(r274291): Missing diagnostic for return of std::unique_ptr<Derived> in C++11 #30809

Open
@llvmbot

Description

@llvmbot
Bugzilla Link 31461
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@nico,@zygoloid

Extended Description

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++

Expected:

$ 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)
...

Actual:

$ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++11clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.waiting-for-wg21Blocked on C++ Standards Committee

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions