1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This is a "No Compile Test" suite. 6// http://dev.chromium.org/developers/testing/no-compile-tests 7 8#include "base/memory/scoped_ptr.h" 9 10#include <utility> 11 12#include "base/macros.h" 13#include "base/memory/ref_counted.h" 14 15namespace { 16 17class Parent { 18}; 19 20class Child : public Parent { 21}; 22 23class RefCountedClass : public base::RefCountedThreadSafe<RefCountedClass> { 24}; 25 26} // namespace 27 28#if defined(NCTEST_NO_PASS_DOWNCAST) // [r"fatal error: no viable conversion from returned value of type 'scoped_ptr<\(anonymous namespace\)::Parent>' to function return type 'scoped_ptr<\(anonymous namespace\)::Child>'"] 29 30scoped_ptr<Child> DowncastUsingPassAs(scoped_ptr<Parent> object) { 31 return object; 32} 33 34#elif defined(NCTEST_NO_REF_COUNTED_SCOPED_PTR) // [r"fatal error: static_assert failed \"T is a refcounted type and needs a scoped_refptr\""] 35 36// scoped_ptr<> should not work for ref-counted objects. 37void WontCompile() { 38 scoped_ptr<RefCountedClass> x; 39} 40 41#elif defined(NCTEST_NO_ARRAY_WITH_SIZE) // [r"fatal error: static_assert failed \"scoped_ptr doesn't support array with size\""] 42 43void WontCompile() { 44 scoped_ptr<int[10]> x; 45} 46 47#elif defined(NCTEST_NO_PASS_FROM_ARRAY) // [r"fatal error: no viable overloaded '='"] 48 49void WontCompile() { 50 scoped_ptr<int[]> a; 51 scoped_ptr<int*> b; 52 b = std::move(a); 53} 54 55#elif defined(NCTEST_NO_PASS_TO_ARRAY) // [r"fatal error: no viable overloaded '='"] 56 57void WontCompile() { 58 scoped_ptr<int*> a; 59 scoped_ptr<int[]> b; 60 b = std::move(a); 61} 62 63#elif defined(NCTEST_NO_CONSTRUCT_FROM_ARRAY) // [r"fatal error: no matching constructor for initialization of 'scoped_ptr<int \*>'"] 64 65void WontCompile() { 66 scoped_ptr<int[]> a; 67 scoped_ptr<int*> b(std::move(a)); 68} 69 70#elif defined(NCTEST_NO_CONSTRUCT_TO_ARRAY) // [r"fatal error: no matching constructor for initialization of 'scoped_ptr<int \[\]>'"] 71 72void WontCompile() { 73 scoped_ptr<int*> a; 74 scoped_ptr<int[]> b(std::move(a)); 75} 76 77#elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_NULL) // [r"is ambiguous"] 78 79void WontCompile() { 80 scoped_ptr<int[]> x(NULL); 81} 82 83#elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_DERIVED) // [r"fatal error: calling a private constructor of class 'scoped_ptr<\(anonymous namespace\)::Parent \[\], std::default_delete<\(anonymous namespace\)::Parent \[\]> >'"] 84 85void WontCompile() { 86 scoped_ptr<Parent[]> x(new Child[1]); 87} 88 89#elif defined(NCTEST_NO_RESET_SCOPED_PTR_ARRAY_FROM_NULL) // [r"is ambiguous"] 90 91void WontCompile() { 92 scoped_ptr<int[]> x; 93 x.reset(NULL); 94} 95 96#elif defined(NCTEST_NO_RESET_SCOPED_PTR_ARRAY_FROM_DERIVED) // [r"fatal error: 'reset' is a private member of 'scoped_ptr<\(anonymous namespace\)::Parent \[\], std::default_delete<\(anonymous namespace\)::Parent \[\]> >'"] 97 98void WontCompile() { 99 scoped_ptr<Parent[]> x; 100 x.reset(new Child[1]); 101} 102 103#elif defined(NCTEST_NO_DELETER_REFERENCE) // [r"fatal error: base specifier must name a class"] 104 105struct Deleter { 106 void operator()(int*) {} 107}; 108 109// Current implementation doesn't support Deleter Reference types. Enabling 110// support would require changes to the behavior of the constructors to match 111// including the use of SFINAE to discard the type-converting constructor 112// as per C++11 20.7.1.2.1.19. 113void WontCompile() { 114 Deleter d; 115 int n; 116 scoped_ptr<int*, Deleter&> a(&n, d); 117} 118 119#endif 120