Index: clang-tools-extra/trunk/clangd/Diagnostics.cpp =================================================================== --- clang-tools-extra/trunk/clangd/Diagnostics.cpp +++ clang-tools-extra/trunk/clangd/Diagnostics.cpp @@ -335,6 +335,11 @@ llvm::SmallVector Edits; for (auto &FixIt : Info.getFixItHints()) { + // Follow clang's behavior, don't apply FixIt to the code in macros, + // we are less certain it is the right fix. + if (FixIt.RemoveRange.getBegin().isMacroID() || + FixIt.RemoveRange.getEnd().isMacroID()) + return false; if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), Info.getSourceManager())) return false; Index: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp @@ -215,6 +215,18 @@ "'int *' with an rvalue of type 'int'"))); } +TEST(DiagnosticsTest, NoFixItInMacro) { + Annotations Test(R"cpp( + #define Define(name) void name() {} + + [[Define]](main) + )cpp"); + auto TU = TestTU::withCode(Test.code()); + EXPECT_THAT(TU.build().getDiagnostics(), + ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"), + Not(WithFix(_))))); +} + TEST(DiagnosticsTest, ToLSP) { clangd::Diag D; D.Message = "something terrible happened";