• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2012 The Chromium Authors
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/weak_ptr.h"
9
10namespace base {
11
12struct Producer : SupportsWeakPtr<Producer> {};
13struct DerivedProducer : Producer {};
14struct OtherDerivedProducer : Producer {};
15struct MultiplyDerivedProducer : Producer,
16                                 SupportsWeakPtr<MultiplyDerivedProducer> {};
17struct Unrelated {};
18struct DerivedUnrelated : Unrelated {};
19
20#if defined(NCTEST_AUTO_DOWNCAST)  // [r"no viable conversion from 'WeakPtr<Producer>' to 'WeakPtr<DerivedProducer>'"]
21
22void WontCompile() {
23  Producer f;
24  WeakPtr<Producer> ptr = f.AsWeakPtr();
25  WeakPtr<DerivedProducer> derived_ptr = ptr;
26}
27
28#elif defined(NCTEST_STATIC_DOWNCAST)  // [r"no matching conversion for static_cast from 'WeakPtr<Producer>' to 'WeakPtr<DerivedProducer>'"]
29
30void WontCompile() {
31  Producer f;
32  WeakPtr<Producer> ptr = f.AsWeakPtr();
33  WeakPtr<DerivedProducer> derived_ptr =
34      static_cast<WeakPtr<DerivedProducer> >(ptr);
35}
36
37#elif defined(NCTEST_AUTO_REF_DOWNCAST)  // [r"fatal error: non-const lvalue reference to type 'WeakPtr<DerivedProducer>' cannot bind to a value of unrelated type 'WeakPtr<Producer>'"]
38
39void WontCompile() {
40  Producer f;
41  WeakPtr<Producer> ptr = f.AsWeakPtr();
42  WeakPtr<DerivedProducer>& derived_ptr = ptr;
43}
44
45#elif defined(NCTEST_STATIC_REF_DOWNCAST)  // [r"fatal error: non-const lvalue reference to type 'WeakPtr<DerivedProducer>' cannot bind to a value of unrelated type 'WeakPtr<Producer>'"]
46
47void WontCompile() {
48  Producer f;
49  WeakPtr<Producer> ptr = f.AsWeakPtr();
50  WeakPtr<DerivedProducer>& derived_ptr =
51      static_cast<WeakPtr<DerivedProducer>&>(ptr);
52}
53
54#elif defined(NCTEST_STATIC_ASWEAKPTR_DOWNCAST)  // [r"no matching function"]
55
56void WontCompile() {
57  Producer f;
58  WeakPtr<DerivedProducer> ptr =
59      SupportsWeakPtr<Producer>::StaticAsWeakPtr<DerivedProducer>(&f);
60}
61
62#elif defined(NCTEST_UNSAFE_HELPER_DOWNCAST)  // [r"no viable conversion from 'WeakPtr<base::Producer>' to 'WeakPtr<DerivedProducer>'"]
63
64void WontCompile() {
65  Producer f;
66  WeakPtr<DerivedProducer> ptr = AsWeakPtr(&f);
67}
68
69#elif defined(NCTEST_UNSAFE_INSTANTIATED_HELPER_DOWNCAST)  // [r"no matching function"]
70
71void WontCompile() {
72  Producer f;
73  WeakPtr<DerivedProducer> ptr = AsWeakPtr<DerivedProducer>(&f);
74}
75
76#elif defined(NCTEST_UNSAFE_WRONG_INSANTIATED_HELPER_DOWNCAST)  // [r"no viable conversion from 'WeakPtr<base::Producer>' to 'WeakPtr<DerivedProducer>'"]
77
78void WontCompile() {
79  Producer f;
80  WeakPtr<DerivedProducer> ptr = AsWeakPtr<Producer>(&f);
81}
82
83#elif defined(NCTEST_UNSAFE_HELPER_CAST)  // [r"no viable conversion from 'WeakPtr<base::DerivedProducer>' to 'WeakPtr<OtherDerivedProducer>'"]
84
85void WontCompile() {
86  DerivedProducer f;
87  WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr(&f);
88}
89
90#elif defined(NCTEST_UNSAFE_INSTANTIATED_HELPER_SIDECAST)  // [r"fatal error: no matching function for call to 'AsWeakPtr'"]
91
92void WontCompile() {
93  DerivedProducer f;
94  WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr<OtherDerivedProducer>(&f);
95}
96
97#elif defined(NCTEST_UNSAFE_WRONG_INSTANTIATED_HELPER_SIDECAST)  // [r"no viable conversion from 'WeakPtr<base::DerivedProducer>' to 'WeakPtr<OtherDerivedProducer>'"]
98
99void WontCompile() {
100  DerivedProducer f;
101  WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr<DerivedProducer>(&f);
102}
103
104#elif defined(NCTEST_UNRELATED_HELPER)  // [r"no viable conversion from 'WeakPtr<base::DerivedProducer>' to 'WeakPtr<Unrelated>'"]
105
106void WontCompile() {
107  DerivedProducer f;
108  WeakPtr<Unrelated> ptr = AsWeakPtr(&f);
109}
110
111#elif defined(NCTEST_UNRELATED_INSTANTIATED_HELPER)  // [r"no matching function"]
112
113void WontCompile() {
114  DerivedProducer f;
115  WeakPtr<Unrelated> ptr = AsWeakPtr<Unrelated>(&f);
116}
117
118#elif defined(NCTEST_COMPLETELY_UNRELATED_HELPER)  // [r"fatal error: static assertion failed due to requirement 'std::is_base_of<base::internal::SupportsWeakPtrBase, base::Unrelated>::value': AsWeakPtr argument must inherit from SupportsWeakPtr"]
119
120void WontCompile() {
121  Unrelated f;
122  WeakPtr<Unrelated> ptr = AsWeakPtr(&f);
123}
124
125#elif defined(NCTEST_DERIVED_COMPLETELY_UNRELATED_HELPER)  // [r"fatal error: static assertion failed due to requirement 'std::is_base_of<base::internal::SupportsWeakPtrBase, base::DerivedUnrelated>::value': AsWeakPtr argument must inherit from SupportsWeakPtr"]
126
127void WontCompile() {
128  DerivedUnrelated f;
129  WeakPtr<Unrelated> ptr = AsWeakPtr(&f);
130}
131
132#elif defined(NCTEST_AMBIGUOUS_ANCESTORS)  // [r"fatal error: no matching function for call to 'AsWeakPtrImpl'"]
133
134void WontCompile() {
135  MultiplyDerivedProducer f;
136  WeakPtr<MultiplyDerivedProducer> ptr = AsWeakPtr(&f);
137}
138
139#elif defined(NCTEST_GETMUTABLEWEAKPTR_CONST_T)  // [r"fatal error: no matching member function for call to 'GetMutableWeakPtr'"]
140
141void WontCompile() {
142  Unrelated unrelated;
143  const WeakPtrFactory<const Unrelated> factory(&unrelated);
144  factory.GetMutableWeakPtr();
145}
146
147#elif defined(NCTEST_GETMUTABLEWEAKPTR_NOT_T)  // [r"fatal error: no matching member function for call to 'GetMutableWeakPtr'"]
148
149void WontCompile() {
150  DerivedUnrelated derived_unrelated;
151  const WeakPtrFactory<DerivedUnrelated> factory(&derived_unrelated);
152  factory.GetMutableWeakPtr<Unrelated>();
153}
154
155#endif
156
157}
158