Add test to document clang's built-in nullability-merging across redecls
PiperOrigin-RevId: 543486066
diff --git a/nullability/test/BUILD b/nullability/test/BUILD
index d649606..1190bf4 100644
--- a/nullability/test/BUILD
+++ b/nullability/test/BUILD
@@ -236,6 +236,11 @@
],
)
+nullability_test(
+ name = "types",
+ srcs = ["types.cc"],
+)
+
cc_test(
name = "variance",
srcs = ["variance.cc"],
diff --git a/nullability/test/types.cc b/nullability/test/types.cc
new file mode 100644
index 0000000..036f9c2
--- /dev/null
+++ b/nullability/test/types.cc
@@ -0,0 +1,19 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Tests for static types of declarations.
+
+#include "nullability_test.h"
+
+// Clang performs merging of nullability attributes on function parameter types.
+// This isn't necessarily desirable: it only works with _Nullable, and only on
+// pointer parameters, not return types, nested types, etc.
+int *merged(int *, int *);
+int *_Nullable merged(int *_Nullable, int *);
+int *merged(int *, Nullable<int *>);
+TEST int *merged(int *a, int *b) {
+ type<Nullable<int *>>(a); // _Nullable attributes are merged
+ type<int *>(b); // clang::annotate-based attributes are not merged
+ type<int *>(merged(a, b)); // return types are not merged
+}