[nullability] Define `__assert_nullability` centrally.
We now always prepend the definition of `__assert_nullability` in
`checkDiagnostics()`, so it will be available in all tests.
PiperOrigin-RevId: 522324205
diff --git a/nullability_verification/test/check_diagnostics.cc b/nullability_verification/test/check_diagnostics.cc
index d830671..328e7ec 100644
--- a/nullability_verification/test/check_diagnostics.cc
+++ b/nullability_verification/test/check_diagnostics.cc
@@ -15,6 +15,17 @@
namespace tidy {
namespace nullability {
+constexpr char kPreamble[] = R"cc(
+ enum NullabilityKind {
+ NK_nonnull,
+ NK_nullable,
+ NK_unspecified,
+ };
+
+ template <NullabilityKind... NK, typename T>
+ void __assert_nullability(const T&);
+)cc";
+
bool checkDiagnostics(llvm::StringRef SourceCode) {
std::vector<CFGElement> Diagnostics;
PointerNullabilityDiagnoser Diagnoser;
@@ -35,8 +46,10 @@
Diagnostics.push_back(EltDiagnostics.value());
}
})
+ .withASTBuildVirtualMappedFiles({{"preamble.h", kPreamble}})
.withASTBuildArgs({"-fsyntax-only", "-std=c++17",
- "-Wno-unused-value", "-Wno-nonnull"}),
+ "-Wno-unused-value", "-Wno-nonnull",
+ "-include", "preamble.h"}),
[&Diagnostics, &Failed](
const llvm::DenseMap<unsigned, std::string> &Annotations,
const dataflow::test::AnalysisOutputs &AnalysisData) {