https://github.com/zeyi2 created 
https://github.com/llvm/llvm-project/pull/198093

None

>From 66c8a8ab7c8f5d58c93f9b610d486294e9e2148e Mon Sep 17 00:00:00 2001
From: Zeyi Xu <[email protected]>
Date: Sat, 16 May 2026 23:00:19 +0800
Subject: [PATCH] [clang-tidy] Fix modernize-macro-to-enum testcases

---
 .../macro-to-enum/modernize-macro-to-enum3.h      |  8 ++++++++
 .../checkers/modernize/macro-to-enum-headers.cpp  | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-headers.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/modernize-macro-to-enum3.h
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/modernize-macro-to-enum3.h
index a9f1fb7e0fa47..3073a4ccaa3da 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/modernize-macro-to-enum3.h
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/modernize-macro-to-enum3.h
@@ -17,4 +17,12 @@
 #define RR3_RED 1
 #define RR3_GREEN 2
 #define RR3_BLUE 3
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: replace macro with enum
+// CHECK-MESSAGES: :[[@LINE-3]]:9: warning: macro 'RR3_GREEN' defines an 
integral constant; prefer an enum instead
+// CHECK-MESSAGES: :[[@LINE-3]]:9: warning: macro 'RR3_BLUE' defines an 
integral constant; prefer an enum instead
+// CHECK-FIXES: #define RR3_RED 1
+// CHECK-FIXES-NEXT: enum {
+// CHECK-FIXES-NEXT: RR3_GREEN = 2,
+// CHECK-FIXES-NEXT: RR3_BLUE = 3
+// CHECK-FIXES-NEXT: };
 #endif
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-headers.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-headers.cpp
new file mode 100644
index 0000000000000..5b51c9806a040
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-headers.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy -std=c++14-or-later \
+// RUN:   -check-header %S/Inputs/macro-to-enum/modernize-macro-to-enum.h \
+// RUN:   -check-header %S/Inputs/macro-to-enum/modernize-macro-to-enum2.h \
+// RUN:   -check-header %S/Inputs/macro-to-enum/modernize-macro-to-enum3.h \
+// RUN:   %s modernize-macro-to-enum %t -- \
+// RUN:   -- -I%S/Inputs/macro-to-enum -fno-delayed-template-parsing
+
+#define HEADER_MAIN 42
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: replace macro with enum 
[modernize-macro-to-enum]
+// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: macro 'HEADER_MAIN' defines an 
integral constant; prefer an enum instead
+// CHECK-FIXES: enum {
+// CHECK-FIXES-NEXT: HEADER_MAIN = 42
+// CHECK-FIXES-NEXT: };
+
+#include "modernize-macro-to-enum.h"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to