Home | History | Annotate | Download | only in unique.ptr.single.asgn
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <memory>
     11 
     12 // unique_ptr
     13 
     14 // Test unique_ptr move assignment
     15 
     16 #include <memory>
     17 
     18 #include "test_macros.h"
     19 
     20 struct Deleter {
     21     void operator()(int* p) {delete p;}
     22 };
     23 
     24 // Can't copy from a const lvalue
     25 int main()
     26 {
     27     const std::unique_ptr<int, Deleter> s(new int);
     28     std::unique_ptr<int, Deleter> s2;
     29 #if TEST_STD_VER >= 11
     30     s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
     31 #else
     32     // NOTE: The error says "constructor" because the assignment operator takes
     33     // 's' by value and attempts to copy construct it.
     34     s2 = s; // expected-error {{no matching constructor for initialization}}
     35 #endif
     36 }
     37