move_convert14.fail.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com//===----------------------------------------------------------------------===// 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// ��������������������The LLVM Compiler Infrastructure 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// This file is distributed under the University of Illinois Open Source 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// License. See LICENSE.TXT for details. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//===----------------------------------------------------------------------===// 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org// <memory> 118b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org 12b83b6b4f7690fe929d8d6b1a3d2b7ed562b95ba6robertphillips@google.com// unique_ptr 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1430da745bbf67a0ee0f305ca7bbdb685cc8a9e686reed@google.com// Test unique_ptr converting move ctor 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// test converting move ctor. Should only require a MoveConstructible deleter, or if 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// deleter is a reference, not even that. 189fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed// Explicit version 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <memory> 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <cassert> 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "../../deleter.h" 249fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed 259fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reedstruct A 26c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com{ 27c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com static int count; 28c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com A() {++count;} 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com A(const A&) {++count;} 309fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed virtual ~A() {--count;} 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 329fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed 339fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reedint A::count = 0; 349fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed 359fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reedstruct B 369fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed : public A 379fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed{ 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static int count; 399fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed B() {++count;} 40c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com B(const B&) {++count;} 419fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed virtual ~B() {--count;} 42c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com}; 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint B::count = 0; 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4630da745bbf67a0ee0f305ca7bbdb685cc8a9e686reed@google.comint main() 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com std::unique_ptr<B[], Deleter<B[]> > s(new B); 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com A* p = s.get(); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s)); 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com assert(s2.get() == p); 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com assert(s.get() == 0); 541447c6f7f4579942b32af6ffff1eadede40b42bctomhudson@google.com assert(A::count == 1); 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com assert(B::count == 1); 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com assert(s2.get_deleter().state() == 5); 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com assert(s.get_deleter().state() == 0); 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 5930da745bbf67a0ee0f305ca7bbdb685cc8a9e686reed@google.com assert(A::count == 0); 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com assert(B::count == 0); 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com