move constructor

Hi,

In my project I'm using make_unique along with unique_ptrs but am getting some errors in the code analysis that are not really errors, ie:

unique_ptr<Foo> a = make_unique<Foo>();

Shows the error:

`unique_ptr::operator=(const unique_ptr&)' is deleted

While this is true, the above uses the move constructor not the copy constructor.

Is this a known issue, and if so is there a fix in the pipeline? It's not a major issue but it's annoying to see errors in the code that aren't really there.

Cheers.

0

Hi Jonathan!

I can't reproduce your issue in my environment. Could you please specify your CLion version, OS, the compiler you're using, and provide a sample program to reproduce the issue? The following program does not produce the warning for me (CLion 1.1.1, clang, OS X):

 
#include <memory>

struct Foo {};

int
main() {
    std::unique_ptr<Foo> a = std::make_unique<Foo>();
    return 0;
}
0
Avatar
Permanently deleted user

Hi Anna,

Sorry it's taken a few days - i've just come back to this project today.

Trying to replicate the issue it seems it only happens when i'm trying to assign the unique_ptr to a member variable.

In the below example the f_, and g_ assignments both give the warning, but the h assignment in main is fine.

Please note that i've got my own version of make_unique as the version of GCC i'm using doesn't include one.

I'm using CLion 1.1.1, on Linux Mint 17.2 and GCC 4.8.4

#include <memory>

using namespace std;

template<class T, class... Args>
std::unique_ptr<T> make_unique(Args&& ... args)
{
    return std::unique_ptr<T>(new T { std::forward<Args>(args)... });
};

class Foo
{
public:
    Foo(int x) : x_(x) {}
private:
    int x_;
};

class
Bar {
public:
    Bar()
    {
        f_ = make_unique<Foo>(0);
        g_
= unique_ptr<Foo>{ new Foo{ 0 } };
    
}
private:
    unique_ptr<Foo> f_;
    unique_ptr
<Foo> g_;
};

int
main() {
    auto h = make_unique<Foo>(0);
    return 0;
}
0

Hi Jonathan.

Thanks for the details! It’s not working correctly, because CLion doesn’t support variadic templates yet. Feel free to comment or upvote the issue in the tracker: https://youtrack.jetbrains.com/issue/CPP-1644.
0

请先登录再写评论。