|
14 | 14 |
|
15 | 15 | #include "absl/base/nullability.h" |
16 | 16 |
|
17 | | -#include <cassert> |
18 | 17 | #include <memory> |
19 | 18 | #include <type_traits> |
20 | 19 | #include <utility> |
21 | 20 |
|
22 | 21 | #include "gtest/gtest.h" |
23 | | -#include "absl/base/attributes.h" |
24 | 22 |
|
25 | 23 | namespace { |
26 | | -namespace macro_annotations { |
27 | 24 | void funcWithNonnullArg(int* absl_nonnull /*arg*/) {} |
28 | 25 | template <typename T> |
29 | 26 | void funcWithDeducedNonnullArg(T* absl_nonnull /*arg*/) {} |
@@ -90,117 +87,4 @@ TEST(PassThroughTest, PassesThroughPointerToMemberFunction) { |
90 | 87 | EXPECT_TRUE((std::is_same<absl_nullable T, T>::value)); |
91 | 88 | EXPECT_TRUE((std::is_same<absl_nullability_unknown T, T>::value)); |
92 | 89 | } |
93 | | -} // namespace macro_annotations |
94 | | - |
95 | | -// Allow testing of the deprecated type alias annotations. |
96 | | -ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING |
97 | | - |
98 | | -using ::absl::Nonnull; |
99 | | -using ::absl::NullabilityUnknown; |
100 | | -using ::absl::Nullable; |
101 | | -namespace type_alias_annotations { |
102 | | - |
103 | | -void funcWithNonnullArg(Nonnull<int*> /*arg*/) {} |
104 | | -template <typename T> |
105 | | -void funcWithDeducedNonnullArg(Nonnull<T*> /*arg*/) {} |
106 | | - |
107 | | -TEST(NonnullTest, NonnullArgument) { |
108 | | - int var = 0; |
109 | | - funcWithNonnullArg(&var); |
110 | | - funcWithDeducedNonnullArg(&var); |
111 | | -} |
112 | | - |
113 | | -Nonnull<int*> funcWithNonnullReturn() { |
114 | | - static int var = 0; |
115 | | - return &var; |
116 | | -} |
117 | | - |
118 | | -TEST(NonnullTest, NonnullReturn) { |
119 | | - auto var = funcWithNonnullReturn(); |
120 | | - (void)var; |
121 | | -} |
122 | | - |
123 | | -TEST(PassThroughTest, PassesThroughRawPointerToInt) { |
124 | | - EXPECT_TRUE((std::is_same<Nonnull<int*>, int*>::value)); |
125 | | - EXPECT_TRUE((std::is_same<Nullable<int*>, int*>::value)); |
126 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<int*>, int*>::value)); |
127 | | -} |
128 | | - |
129 | | -TEST(PassThroughTest, PassesThroughRawPointerToVoid) { |
130 | | - EXPECT_TRUE((std::is_same<Nonnull<void*>, void*>::value)); |
131 | | - EXPECT_TRUE((std::is_same<Nullable<void*>, void*>::value)); |
132 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<void*>, void*>::value)); |
133 | | -} |
134 | | - |
135 | | -TEST(PassThroughTest, PassesThroughUniquePointerToInt) { |
136 | | - using T = std::unique_ptr<int>; |
137 | | - EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value)); |
138 | | - EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); |
139 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); |
140 | | -} |
141 | | - |
142 | | -TEST(PassThroughTest, PassesThroughSharedPointerToInt) { |
143 | | - using T = std::shared_ptr<int>; |
144 | | - EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value)); |
145 | | - EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); |
146 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); |
147 | | -} |
148 | | - |
149 | | -TEST(PassThroughTest, PassesThroughSharedPointerToVoid) { |
150 | | - using T = std::shared_ptr<void>; |
151 | | - EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value)); |
152 | | - EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); |
153 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); |
154 | | -} |
155 | | - |
156 | | -TEST(PassThroughTest, PassesThroughPointerToMemberObject) { |
157 | | - using T = decltype(&std::pair<int, int>::first); |
158 | | - EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value)); |
159 | | - EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); |
160 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); |
161 | | -} |
162 | | - |
163 | | -TEST(PassThroughTest, PassesThroughPointerToMemberFunction) { |
164 | | - using T = decltype(&std::unique_ptr<int>::reset); |
165 | | - EXPECT_TRUE((std::is_same<Nonnull<T>, T>::value)); |
166 | | - EXPECT_TRUE((std::is_same<Nullable<T>, T>::value)); |
167 | | - EXPECT_TRUE((std::is_same<NullabilityUnknown<T>, T>::value)); |
168 | | -} |
169 | | - |
170 | | -} // namespace type_alias_annotations |
171 | | -} // namespace |
172 | | - |
173 | | -// Nullable ADL lookup test |
174 | | -namespace util { |
175 | | -// Helper for NullableAdlTest. Returns true, denoting that argument-dependent |
176 | | -// lookup found this implementation of DidAdlWin. Must be in namespace |
177 | | -// util itself, not a nested anonymous namespace. |
178 | | -template <typename T> |
179 | | -bool DidAdlWin(T*) { |
180 | | - return true; |
181 | | -} |
182 | | - |
183 | | -// Because this type is defined in namespace util, an unqualified call to |
184 | | -// DidAdlWin with a pointer to MakeAdlWin will find the above implementation. |
185 | | -struct MakeAdlWin {}; |
186 | | -} // namespace util |
187 | | - |
188 | | -namespace { |
189 | | -// Returns false, denoting that ADL did not inspect namespace util. If it |
190 | | -// had, the better match (T*) above would have won out over the (...) here. |
191 | | -bool DidAdlWin(...) { return false; } |
192 | | - |
193 | | -TEST(NullableAdlTest, NullableAddsNothingToArgumentDependentLookup) { |
194 | | - // Treatment: util::Nullable<int*> contributes nothing to ADL because |
195 | | - // int* itself doesn't. |
196 | | - EXPECT_FALSE(DidAdlWin((int*)nullptr)); |
197 | | - EXPECT_FALSE(DidAdlWin((Nullable<int*>)nullptr)); |
198 | | - |
199 | | - // Control: Argument-dependent lookup does find the implementation in |
200 | | - // namespace util when the underlying pointee type resides there. |
201 | | - EXPECT_TRUE(DidAdlWin((util::MakeAdlWin*)nullptr)); |
202 | | - EXPECT_TRUE(DidAdlWin((Nullable<util::MakeAdlWin*>)nullptr)); |
203 | | -} |
204 | | - |
205 | | -ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING |
206 | 90 | } // namespace |
0 commit comments