Skip to content

Commit 8266cd9

Browse files
[clangd] Disable cppcoreguidelines-macro-to-enum clang-tidy checker (llvm#129478)
Clangd does not support its checker because the checker relies on having seen preprocessor conditionals that occur in the preamble, and clangd does not currently replay those. This checker was already disabled under its main name, modernize-macro-to-enum (clangd/clangd#1464). This commit disables it under the alternative name cppcoreguidelines-macro-to-enum as well. Fixes llvm#127965
1 parent 80bdfcd commit 8266cd9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang-tools-extra/clangd/TidyProvider.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks) {
210210
// Check relies on seeing ifndef/define/endif directives,
211211
// clangd doesn't replay those when using a preamble.
212212
"-llvm-header-guard", "-modernize-macro-to-enum",
213+
"-cppcoreguidelines-macro-to-enum",
213214

214215
// ----- Crashing Checks -----
215216

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,21 @@ TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) {
823823
EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
824824
}
825825

826+
TEST(DiagnosticTest, ClangTidyMacroToEnumCheck) {
827+
Annotations Main(R"cpp(
828+
#if 1
829+
auto foo();
830+
#endif
831+
)cpp");
832+
TestTU TU = TestTU::withCode(Main.code());
833+
std::vector<TidyProvider> Providers;
834+
Providers.push_back(
835+
addTidyChecks("cppcoreguidelines-macro-to-enum,modernize-macro-to-enum"));
836+
Providers.push_back(disableUnusableChecks());
837+
TU.ClangTidyProvider = combine(std::move(Providers));
838+
EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
839+
}
840+
826841
TEST(DiagnosticTest, ElseAfterReturnRange) {
827842
Annotations Main(R"cpp(
828843
int foo(int cond) {

0 commit comments

Comments
 (0)