xref: /aosp_15_r20/external/angle/third_party/abseil-cpp/absl/base/internal/nullability_impl.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 // Copyright 2023 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
16 #define ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
17 
18 #include <memory>
19 #include <type_traits>
20 
21 #include "absl/base/attributes.h"
22 #include "absl/base/config.h"
23 #include "absl/meta/type_traits.h"
24 
25 namespace absl {
26 ABSL_NAMESPACE_BEGIN
27 namespace nullability_internal {
28 
29 template <typename T>
30 using NullableImpl
31 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
32     [[clang::annotate("Nullable")]]
33 #endif
34 // Don't add the _Nullable attribute in Objective-C compiles. Many Objective-C
35 // projects enable the `-Wnullable-to-nonnull-conversion warning`, which is
36 // liable to produce false positives.
37 #if ABSL_HAVE_FEATURE(nullability_on_classes) && !defined(__OBJC__)
38     = T _Nullable;
39 #else
40     = T;
41 #endif
42 
43 template <typename T>
44 using NonnullImpl
45 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
46     [[clang::annotate("Nonnull")]]
47 #endif
48 #if ABSL_HAVE_FEATURE(nullability_on_classes) && !defined(__OBJC__)
49     = T _Nonnull;
50 #else
51     = T;
52 #endif
53 
54 template <typename T>
55 using NullabilityUnknownImpl
56 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::annotate)
57     [[clang::annotate("Nullability_Unspecified")]]
58 #endif
59 #if ABSL_HAVE_FEATURE(nullability_on_classes) && !defined(__OBJC__)
60     = T _Null_unspecified;
61 #else
62     = T;
63 #endif
64 
65 }  // namespace nullability_internal
66 ABSL_NAMESPACE_END
67 }  // namespace absl
68 
69 #endif  // ABSL_BASE_INTERNAL_NULLABILITY_IMPL_H_
70