martinmoene / value-ptr-lite

value-ptr-lite - A C++ smart-pointer with value semantics for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
48 stars 14 forks source link

Problem with move assignment operator #6

Closed Grismolk closed 5 years ago

Grismolk commented 5 years ago

Hello. Compile time error in this case:

nonstd::value_ptr<double> vptr1 = 10.01;
nonstd::value_ptr<double> vptr2 = 20.02;

vptr2 = std::move(vptr1);

std::cout << vptr2.value() << std::endl;
std::cout << vptr1.value() << std::endl;

Edited(mm): added c++ codeblock delimiters

martinmoene commented 5 years ago
#include "nonstd/value_ptr.hpp"
#include <iostream>

int main()
{    
    nonstd::value_ptr<double> vptr1 = 10.01;
    nonstd::value_ptr<double> vptr2 = 20.02;

    vptr2 = nonstd::value_ptr<double>(30.03);  // L9: does not compile
    vptr2 = std::move(vptr1);                  // L10: does not compile

    std::cout << vptr2.value() << std::endl;
    std::cout << vptr1.value() << std::endl;
}

Compiling with:

clang-cl -std:c++14 -EHsc -I../include/ issue-6-move-assignment.cpp

Yields:

In file included from issue-6-move-assignment.cpp:1:

../include\nonstd/value_ptr.hpp(764,13):  error: no matching member function for call to 'reset'
        ptr.reset( std::move( rhs.ptr ) );
        ~~~~^~~~~

issue-6-move-assignment.cpp(9,11): note: in instantiation of member function

'nonstd::vptr::value_ptr<double,
      nonstd::vptr::detail::default_clone<double>, std::default_delete<double> >::operator=' requested here
    vptr2 = nonstd::value_ptr<double>(30.03);
          ^

../include\nonstd/value_ptr.hpp(547,10):

note: candidate function not viable: no known conversion from

'remove_reference_t
<
    nonstd::vptr::detail::compressed_ptr
    <
        double
        , nonstd::vptr::detail::default_clone<double>
        , std::default_delete<double> 
    > &
>' 

(aka 'nonstd::vptr::detail::compressed_ptr<double, nonstd::vptr::detail::default_clone, std::default_delete >')

to

'nonstd::vptr::detail::compressed_ptr
<
    double
    , nonstd::vptr::detail::default_clone<double>
    ,std::default_delete<double> 
>::pointer' 

(aka 'double *')

for 1st argument void reset( pointer p ) nsvp_noexcept

Grismolk commented 5 years ago

Thanks