Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is a "No Compile Test" suite. | 5 // This is a "No Compile Test" suite. |
| 6 // http://dev.chromium.org/developers/testing/no-compile-tests | 6 // http://dev.chromium.org/developers/testing/no-compile-tests |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class Parent { | 14 class Parent { |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 class Child : public Parent { | 17 class Child : public Parent { |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 class RefCountedClass : public base::RefCountedThreadSafe<RefCountedClass> { | 20 class RefCountedClass : public base::RefCountedThreadSafe<RefCountedClass> { |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 #if defined(NCTEST_NO_PASS_DOWNCAST) // [r"fatal error: no viable conversion fr om returned value of type 'scoped_ptr<\(anonymous namespace\)::Parent, default_d elete<\(anonymous namespace\)::Parent>>' to function return type 'scoped_ptr<\(a nonymous namespace\)::Child, default_delete<\(anonymous namespace\)::Child>>'"] | 25 #if defined(NCTEST_NO_PASS_DOWNCAST) // [r"fatal error: no viable conversion fr om returned value of type 'scoped_ptr<\(anonymous namespace\)::Parent, default_d elete<\(anonymous namespace\)::Parent>>' to function return type 'scoped_ptr<\(a nonymous namespace\)::Child, default_delete<\(anonymous namespace\)::Child>>'"] |
| 26 | 26 |
| 27 scoped_ptr<Child> DowncastUsingPassAs(scoped_ptr<Parent> object) { | 27 scoped_ptr<Child> DowncastUsingPassAs(scoped_ptr<Parent> object) { |
| 28 return object.Pass(); | 28 return std::move(object); |
|
dcheng
2015/12/31 10:24:53
#include <utility>
tzik
2015/12/31 11:10:46
Done.
| |
| 29 } | 29 } |
| 30 | 30 |
| 31 #elif defined(NCTEST_NO_REF_COUNTED_SCOPED_PTR) // [r"fatal error: static_asser t failed \"T is a refcounted type and needs a scoped_refptr\""] | 31 #elif defined(NCTEST_NO_REF_COUNTED_SCOPED_PTR) // [r"fatal error: static_asser t failed \"T is a refcounted type and needs a scoped_refptr\""] |
| 32 | 32 |
| 33 // scoped_ptr<> should not work for ref-counted objects. | 33 // scoped_ptr<> should not work for ref-counted objects. |
| 34 void WontCompile() { | 34 void WontCompile() { |
| 35 scoped_ptr<RefCountedClass> x; | 35 scoped_ptr<RefCountedClass> x; |
| 36 } | 36 } |
| 37 | 37 |
| 38 #elif defined(NCTEST_NO_ARRAY_WITH_SIZE) // [r"fatal error: static_assert faile d \"scoped_ptr doesn't support array with size\""] | 38 #elif defined(NCTEST_NO_ARRAY_WITH_SIZE) // [r"fatal error: static_assert faile d \"scoped_ptr doesn't support array with size\""] |
| 39 | 39 |
| 40 void WontCompile() { | 40 void WontCompile() { |
| 41 scoped_ptr<int[10]> x; | 41 scoped_ptr<int[10]> x; |
| 42 } | 42 } |
| 43 | 43 |
| 44 #elif defined(NCTEST_NO_PASS_FROM_ARRAY) // [r"fatal error: no viable overloade d '='"] | 44 #elif defined(NCTEST_NO_PASS_FROM_ARRAY) // [r"fatal error: no viable overloade d '='"] |
| 45 | 45 |
| 46 void WontCompile() { | 46 void WontCompile() { |
| 47 scoped_ptr<int[]> a; | 47 scoped_ptr<int[]> a; |
| 48 scoped_ptr<int*> b; | 48 scoped_ptr<int*> b; |
| 49 b = a.Pass(); | 49 b = std::move(a); |
| 50 } | 50 } |
| 51 | 51 |
| 52 #elif defined(NCTEST_NO_PASS_TO_ARRAY) // [r"fatal error: no viable overloaded '='"] | 52 #elif defined(NCTEST_NO_PASS_TO_ARRAY) // [r"fatal error: no viable overloaded '='"] |
| 53 | 53 |
| 54 void WontCompile() { | 54 void WontCompile() { |
| 55 scoped_ptr<int*> a; | 55 scoped_ptr<int*> a; |
| 56 scoped_ptr<int[]> b; | 56 scoped_ptr<int[]> b; |
| 57 b = a.Pass(); | 57 b = std::move(a); |
| 58 } | 58 } |
| 59 | 59 |
| 60 #elif defined(NCTEST_NO_CONSTRUCT_FROM_ARRAY) // [r"fatal error: no matching co nstructor for initialization of 'scoped_ptr<int \*>'"] | 60 #elif defined(NCTEST_NO_CONSTRUCT_FROM_ARRAY) // [r"fatal error: no matching co nstructor for initialization of 'scoped_ptr<int \*>'"] |
| 61 | 61 |
| 62 void WontCompile() { | 62 void WontCompile() { |
| 63 scoped_ptr<int[]> a; | 63 scoped_ptr<int[]> a; |
| 64 scoped_ptr<int*> b(a.Pass()); | 64 scoped_ptr<int*> b(std::move(a)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 #elif defined(NCTEST_NO_CONSTRUCT_TO_ARRAY) // [r"fatal error: no matching cons tructor for initialization of 'scoped_ptr<int \[\]>'"] | 67 #elif defined(NCTEST_NO_CONSTRUCT_TO_ARRAY) // [r"fatal error: no matching cons tructor for initialization of 'scoped_ptr<int \[\]>'"] |
| 68 | 68 |
| 69 void WontCompile() { | 69 void WontCompile() { |
| 70 scoped_ptr<int*> a; | 70 scoped_ptr<int*> a; |
| 71 scoped_ptr<int[]> b(a.Pass()); | 71 scoped_ptr<int[]> b(std::move(a)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 #elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_NULL) // [r"is ambiguou s"] | 74 #elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_NULL) // [r"is ambiguou s"] |
| 75 | 75 |
| 76 void WontCompile() { | 76 void WontCompile() { |
| 77 scoped_ptr<int[]> x(NULL); | 77 scoped_ptr<int[]> x(NULL); |
| 78 } | 78 } |
| 79 | 79 |
| 80 #elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_DERIVED) // [r"fatal er ror: calling a private constructor of class 'scoped_ptr<\(anonymous namespace\): :Parent \[\], std::default_delete<\(anonymous namespace\)::Parent \[\]> >'"] | 80 #elif defined(NCTEST_NO_CONSTRUCT_SCOPED_PTR_ARRAY_FROM_DERIVED) // [r"fatal er ror: calling a private constructor of class 'scoped_ptr<\(anonymous namespace\): :Parent \[\], std::default_delete<\(anonymous namespace\)::Parent \[\]> >'"] |
| 81 | 81 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 107 // support would require changes to the behavior of the constructors to match | 107 // support would require changes to the behavior of the constructors to match |
| 108 // including the use of SFINAE to discard the type-converting constructor | 108 // including the use of SFINAE to discard the type-converting constructor |
| 109 // as per C++11 20.7.1.2.1.19. | 109 // as per C++11 20.7.1.2.1.19. |
| 110 void WontCompile() { | 110 void WontCompile() { |
| 111 Deleter d; | 111 Deleter d; |
| 112 int n; | 112 int n; |
| 113 scoped_ptr<int*, Deleter&> a(&n, d); | 113 scoped_ptr<int*, Deleter&> a(&n, d); |
| 114 } | 114 } |
| 115 | 115 |
| 116 #endif | 116 #endif |
| OLD | NEW |