diff --git a/clang-tools-extra/clangd/unittests/ASTTests.cpp b/clang-tools-extra/clangd/unittests/ASTTests.cpp --- a/clang-tools-extra/clangd/unittests/ASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ASTTests.cpp @@ -37,8 +37,6 @@ for (Test T : Tests) { Annotations File(T.AnnotatedCode); auto AST = TestTU::withCode(File.code()).build(); - ASSERT_TRUE(AST.getDiagnostics().empty()) - << AST.getDiagnostics().begin()->Message; SourceManagerForFile SM("foo.cpp", File.code()); for (Position Pos : File.points()) { diff --git a/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp b/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp --- a/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp +++ b/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp @@ -65,7 +65,7 @@ #define $2[[PREPEND]](X) MACRO##X() #define $3[[MACROA]]() 123 int B = $1[[CONCAT]](MACRO); - int D = $2[[PREPEND]](A) + int D = $2[[PREPEND]](A); )cpp", R"cpp( // FIXME: Macro names in a definition are not detected. diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -104,6 +104,7 @@ TEST(DiagnosticsTest, DiagnosticRanges) { // Check we report correct ranges, including various edge-cases. Annotations Test(R"cpp( + // error-ok namespace test{}; void $decl[[foo]](); class T{$explicit[[]]$constructor[[T]](int a);}; @@ -153,7 +154,7 @@ } TEST(DiagnosticsTest, FlagsMatter) { - Annotations Test("[[void]] main() {}"); + Annotations Test("[[void]] main() {} // error-ok"); auto TU = TestTU::withCode(Test.code()); EXPECT_THAT(TU.build().getDiagnostics(), ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"), @@ -170,7 +171,7 @@ TEST(DiagnosticsTest, DiagnosticPreamble) { Annotations Test(R"cpp( - #include $[["not-found.h"]] + #include $[["not-found.h"]] // error-ok )cpp"); auto TU = TestTU::withCode(Test.code()); @@ -290,7 +291,7 @@ Annotations Main(R"cpp( int main() { int i = 3; - double f = [[8]] / i; + double f = [[8]] / i; // error-ok } )cpp"); TestTU TU = TestTU::withCode(Main.code()); @@ -309,6 +310,7 @@ // We limit the size of printed code. Annotations Source(R"cpp( int main() { + // error-ok int somereallyreallyreallyreallyreallyreallyreallyreallylongidentifier; [[omereallyreallyreallyreallyreallyreallyreallyreallylongidentifier]]= 10; } @@ -323,13 +325,14 @@ "'somereallyreallyreallyreallyreallyreallyreallyreal…'")))); // Only show changes up to a first newline. Source = Annotations(R"cpp( + // error-ok int main() { int ident; [[ide\ -n]] = 10; +n]] = 10; // error-ok } )cpp"); - TU = TestTU::withCode(Source.code()); + TU.Code = Source.code(); EXPECT_THAT(TU.build().getDiagnostics(), ElementsAre(WithFix( Fix(Source.range(), "ident", "change 'ide\\…' to 'ident'")))); @@ -339,7 +342,7 @@ Annotations Main(R"cpp( int main() { int i = 3; - double f = [[8]] / i; // NOLINT + double f = [[8]] / i; // NOLINT // error-ok } )cpp"); TestTU TU = TestTU::withCode(Main.code()); @@ -363,7 +366,7 @@ Annotations Test(R"cpp( #ifndef FOO #define FOO - int a = [[b]]; + int a = [[b]]; // error-ok #else int x = y; #endif @@ -379,7 +382,7 @@ #define RET(x) return x + 10 int* foo() { - RET($foo[[0]]); + RET($foo[[0]]); // error-ok } int* bar() { return $bar[[TEN]]; @@ -398,7 +401,7 @@ Annotations Test(R"cpp( #define Define(name) void name() {} - [[Define]](main) + [[Define]](main) // error-ok )cpp"); auto TU = TestTU::withCode(Test.code()); EXPECT_THAT(TU.build().getDiagnostics(), @@ -540,7 +543,7 @@ } TEST(IncludeFixerTest, IncompleteType) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { class X; $nested[[X::]]Nested n; @@ -573,7 +576,7 @@ } TEST(IncludeFixerTest, NoSuggestIncludeWhenNoDefinitionInHeader) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { class X; } @@ -604,7 +607,7 @@ } TEST(IncludeFixerTest, Typo) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { void foo() { $unqualified1[[X]] x; @@ -648,7 +651,7 @@ } TEST(IncludeFixerTest, MultipleMatchedSymbols) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace na { namespace nb { void foo() { @@ -673,7 +676,7 @@ } TEST(IncludeFixerTest, NoCrashMemebrAccess) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok struct X { int xyz; }; void g() { X x; x.$[[xy]] } )cpp"); @@ -690,7 +693,7 @@ TEST(IncludeFixerTest, UseCachedIndexResults) { // As index results for the identical request are cached, more than 5 fixes // are generated. - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]void foo() { $x1[[X]] x; $x2[[X]] x; @@ -729,7 +732,7 @@ } TEST(IncludeFixerTest, UnresolvedNameAsSpecifier) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { } void g() { ns::$[[scope]]::X_Y(); } @@ -751,7 +754,7 @@ } TEST(IncludeFixerTest, UnresolvedSpecifierWithSemaCorrection) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace clang { void f() { // "clangd::" will be corrected to "clang::" by Sema. @@ -797,7 +800,7 @@ } TEST(IncludeFixerTest, SpecifiedScopeIsNamespaceAlias) { - Annotations Test(R"cpp( + Annotations Test(R"cpp(// error-ok $insert[[]]namespace a {} namespace b = a; namespace c { @@ -825,7 +828,7 @@ struct A { Templ s; - A() { [[a]]; } // this caused crashes if we compute scopes lazily. + A() { [[a]]; /*error-ok*/ } // crash if we compute scopes lazily. }; )cpp"); @@ -841,7 +844,7 @@ Annotations Main(R"cpp( #include [["a.h"]] void foo() {})cpp"); - Annotations Header("[[no_type_spec]];"); + Annotations Header("[[no_type_spec]]; // error-ok"); TestTU TU = TestTU::withCode(Main.code()); TU.AdditionalFiles = {{"a.h", Header.code()}}; EXPECT_THAT(TU.build().getDiagnostics(), @@ -856,7 +859,8 @@ #include [["a.h"]] void foo() {})cpp"); TestTU TU = TestTU::withCode(Main.code()); - TU.AdditionalFiles = {{"a.h", "#include \"b.h\""}, {"b.h", "no_type_spec;"}}; + TU.AdditionalFiles = {{"a.h", "#include \"b.h\""}, + {"b.h", "no_type_spec; // error-ok"}}; EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre( Diag(Main.range(), "in included file: C++ requires a " @@ -869,7 +873,8 @@ #include $b[["b.h"]] void foo() {})cpp"); TestTU TU = TestTU::withCode(Main.code()); - TU.AdditionalFiles = {{"a.h", "no_type_spec;"}, {"b.h", "no_type_spec;"}}; + TU.AdditionalFiles = {{"a.h", "no_type_spec; // error-ok"}, + {"b.h", "no_type_spec; // error-ok"}}; EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre( Diag(Main.range("a"), "in included file: C++ requires a type " @@ -884,8 +889,9 @@ #include "b.h" void foo() {})cpp"); TestTU TU = TestTU::withCode(Main.code()); - TU.AdditionalFiles = {{"a.h", "#include \"b.h\"\n"}, - {"b.h", "#ifndef X\n#define X\nno_type_spec;\n#endif"}}; + TU.AdditionalFiles = { + {"a.h", "#include \"b.h\"\n"}, + {"b.h", "#ifndef X\n#define X\nno_type_spec; // error-ok\n#endif"}}; EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre(Diag(Main.range(), "in included file: C++ requires a type " @@ -900,9 +906,10 @@ #include [["b.h"]] void foo() {})cpp"); TestTU TU = TestTU::withCode(Main.code()); - TU.AdditionalFiles = {{"a.h", "#include \"c.h\"\n"}, - {"b.h", "#include \"c.h\"\n"}, - {"c.h", "#ifndef X\n#define X\nno_type_spec;\n#endif"}}; + TU.AdditionalFiles = { + {"a.h", "#include \"c.h\"\n"}, + {"b.h", "#include \"c.h\"\n"}, + {"c.h", "#ifndef X\n#define X\nno_type_spec; // error-ok\n#endif"}}; EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre( Diag(Main.range(), "in included file: C++ requires a " @@ -920,7 +927,7 @@ {"c.h", R"cpp( #ifndef X #define X - no_type_spec_0; + no_type_spec_0; // error-ok no_type_spec_1; no_type_spec_2; no_type_spec_3; @@ -943,7 +950,7 @@ #include [["a.h"]] void foo() {})cpp"); Annotations Header(R"cpp( - [[no_type_spec]]; + [[no_type_spec]]; // error-ok int x = 5/0;)cpp"); TestTU TU = TestTU::withCode(Main.code()); TU.AdditionalFiles = {{"a.h", Header.code()}}; @@ -960,7 +967,7 @@ void foo() {})cpp"); Annotations Header(R"cpp( int x = 5/0; - int b = [[FOO]];)cpp"); + int b = [[FOO]]; // error-ok)cpp"); TestTU TU = TestTU::withCode(Main.code()); TU.AdditionalFiles = {{"a.h", Header.code()}}; TU.ExtraArgs = {"-DFOO=NOOO"}; @@ -974,7 +981,7 @@ TEST(DiagsInHeaders, ErrorFromMacroExpansion) { Annotations Main(R"cpp( void bar() { - int fo; + int fo; // error-ok #include [["a.h"]] })cpp"); Annotations Header(R"cpp( @@ -991,7 +998,7 @@ TEST(DiagsInHeaders, ErrorFromMacroArgument) { Annotations Main(R"cpp( void bar() { - int fo; + int fo; // error-ok #include [["a.h"]] })cpp"); Annotations Header(R"cpp( diff --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp --- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -407,7 +407,6 @@ TestTU TU; TU.HeaderCode = "class Foo{};"; Annotations Main(R"cpp( - #include "foo.h" void f() { [[Foo]] foo; } diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -75,7 +75,6 @@ auto TU = TestTU::withCode(A.code()); TU.ExtraArgs = Flags; auto AST = TU.build(); - EXPECT_THAT(AST.getDiagnostics(), ::testing::IsEmpty()) << Code; llvm::Annotations::Range R = A.range(); SelectionTree Selection(AST.getASTContext(), AST.getTokens(), R.Begin, R.End); @@ -592,11 +591,6 @@ TU.ExtraArgs.push_back("-std=c++2a"); auto AST = TU.build(); - for (auto &D : AST.getDiagnostics()) { - if (D.Severity > DiagnosticsEngine::Warning) - ADD_FAILURE() << D << Code; - } - auto *TestDecl = &findDecl(AST, "foo"); if (auto *T = llvm::dyn_cast(TestDecl)) TestDecl = T->getTemplatedDecl(); diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -563,7 +563,6 @@ TU.ExtraArgs.push_back("-std=c++17"); TU.ExtraArgs.push_back("-fno-delayed-template-parsing"); auto AST = TU.build(); - ASSERT_TRUE(AST.getDiagnostics().empty()); auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr); ASSERT_TRUE(H); @@ -630,8 +629,6 @@ TestTU TU = TestTU::withCode(T.code()); TU.ExtraArgs.push_back("-std=c++17"); auto AST = TU.build(); - ASSERT_TRUE(AST.getDiagnostics().empty()); - auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr); ASSERT_FALSE(H); } @@ -1589,9 +1586,6 @@ TU.ExtraArgs.push_back("-std=c++17"); TU.ExtraArgs.push_back("-Wno-gnu-designator"); auto AST = TU.build(); - for (const auto &D : AST.getDiagnostics()) - ADD_FAILURE() << D; - ASSERT_TRUE(AST.getDiagnostics().empty()); auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get()); ASSERT_TRUE(H); @@ -1626,10 +1620,6 @@ TestTU TU = TestTU::withCode(T.code()); auto AST = TU.build(); - for (const auto &D : AST.getDiagnostics()) - ADD_FAILURE() << D; - ASSERT_TRUE(AST.getDiagnostics().empty()); - Symbol IndexSym; IndexSym.ID = *getSymbolID(&findDecl(AST, "X")); IndexSym.Documentation = "comment from index"; @@ -1663,10 +1653,6 @@ TestTU TU = TestTU::withCode(T.code()); auto AST = TU.build(); - for (const auto &D : AST.getDiagnostics()) - ADD_FAILURE() << D; - ASSERT_TRUE(AST.getDiagnostics().empty()); - for (const auto &P : T.points()) { auto H = getHover(AST, P, format::getLLVMStyle(), nullptr); ASSERT_TRUE(H); @@ -1690,10 +1676,6 @@ TestTU TU = TestTU::withCode(T.code()); auto AST = TU.build(); - for (const auto &D : AST.getDiagnostics()) - ADD_FAILURE() << D; - ASSERT_TRUE(AST.getDiagnostics().empty()); - for (auto Comment : {"doc1", "doc2", "doc3"}) { for (const auto &P : T.points(Comment)) { auto H = getHover(AST, P, format::getLLVMStyle(), nullptr); @@ -1866,9 +1848,6 @@ Annotations T(C.Code); TestTU TU = TestTU::withCode(T.code()); auto AST = TU.build(); - for (const auto &D : AST.getDiagnostics()) - ADD_FAILURE() << D; - auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr); ASSERT_TRUE(H); HoverInfo ExpectedHover; diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -173,6 +173,7 @@ #include "foo.h" first_token; void test() { + // error-ok: invalid syntax, just examining token stream } last_token )cpp"; @@ -236,24 +237,26 @@ // - preamble ends ^ID(int A); // Macro arguments included. - ^MACRO_ARGS(^MACRO_ARGS(^MACRO_EXP(int), A), ^ID(= 2)); + ^MACRO_ARGS(^MACRO_ARGS(^MACRO_EXP(int), E), ^ID(= 2)); // Macro names inside other macros not included. #define ^MACRO_ARGS2(X, Y) X Y #define ^FOO BAR #define ^BAR 1 - int A = ^FOO; + int F = ^FOO; // Macros from token concatenations not included. #define ^CONCAT(X) X##A() #define ^PREPEND(X) MACRO##X() #define ^MACROA() 123 - int B = ^CONCAT(MACRO); - int D = ^PREPEND(A) + int G = ^CONCAT(MACRO); + int H = ^PREPEND(A); // Macros included not from preamble not included. #include "foo.inc" + int printf(const char*, ...); + void exit(int); #define ^assert(COND) if (!(COND)) { printf("%s", #COND); exit(0); } void test() { diff --git a/clang-tools-extra/clangd/unittests/PrintASTTests.cpp b/clang-tools-extra/clangd/unittests/PrintASTTests.cpp --- a/clang-tools-extra/clangd/unittests/PrintASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/PrintASTTests.cpp @@ -81,7 +81,7 @@ template