xref: /aosp_15_r20/external/angle/third_party/abseil-cpp/absl/base/nullability_default_nonnull_test.cc (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 // Copyright 2024 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 #include <cassert>
16 
17 #include "gtest/gtest.h"
18 #include "absl/base/nullability.h"
19 
20 ABSL_POINTERS_DEFAULT_NONNULL
21 
22 namespace {
23 
FuncWithDefaultNonnullArg(int *)24 void FuncWithDefaultNonnullArg(int* /*arg*/) {}
25 template <typename T>
FuncWithDeducedDefaultNonnullArg(T *)26 void FuncWithDeducedDefaultNonnullArg(T* /*arg*/) {}
27 
TEST(DefaultNonnullTest,NonnullArgument)28 TEST(DefaultNonnullTest, NonnullArgument) {
29   int var = 0;
30   FuncWithDefaultNonnullArg(&var);
31   FuncWithDeducedDefaultNonnullArg<int>(&var);
32 }
33 
FuncWithDefaultNonnullReturn()34 int* FuncWithDefaultNonnullReturn() {
35   static int var = 0;
36   return &var;
37 }
38 
TEST(DefaultNonnullTest,NonnullReturn)39 TEST(DefaultNonnullTest, NonnullReturn) {
40   auto var = FuncWithDefaultNonnullReturn();
41   (void)var;
42 }
43 
44 }  // namespace
45