[clang-tools-extra] [clang-tidy][NFC] Do less unnecessary work in `modernize-deprecated-headers` (PR #160967)

Nicolas van Kempen via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 1 21:04:31 PDT 2025


================
@@ -131,48 +131,38 @@ void DeprecatedHeadersCheck::check(
 }
 
 IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
-    std::vector<IncludeMarker> &IncludesToBeProcessed, LangOptions LangOpts,
-    const SourceManager &SM, bool CheckHeaderFile)
-    : IncludesToBeProcessed(IncludesToBeProcessed), LangOpts(LangOpts), SM(SM),
+    std::vector<IncludeMarker> &IncludesToBeProcessed,
+    const LangOptions &LangOpts, const SourceManager &SM, bool CheckHeaderFile)
+    : IncludesToBeProcessed(IncludesToBeProcessed), SM(SM),
       CheckHeaderFile(CheckHeaderFile) {
-  for (const auto &KeyValue :
-       std::vector<std::pair<llvm::StringRef, std::string>>(
-           {{"assert.h", "cassert"},
-            {"complex.h", "complex"},
-            {"ctype.h", "cctype"},
-            {"errno.h", "cerrno"},
-            {"float.h", "cfloat"},
-            {"limits.h", "climits"},
-            {"locale.h", "clocale"},
-            {"math.h", "cmath"},
-            {"setjmp.h", "csetjmp"},
-            {"signal.h", "csignal"},
-            {"stdarg.h", "cstdarg"},
-            {"stddef.h", "cstddef"},
-            {"stdio.h", "cstdio"},
-            {"stdlib.h", "cstdlib"},
-            {"string.h", "cstring"},
-            {"time.h", "ctime"},
-            {"wchar.h", "cwchar"},
-            {"wctype.h", "cwctype"}})) {
+
+  static constexpr std::pair<StringRef, StringRef> CXX98Headers[] = {
+      {"assert.h", "cassert"}, {"complex.h", "complex"},
+      {"ctype.h", "cctype"},   {"errno.h", "cerrno"},
+      {"float.h", "cfloat"},   {"limits.h", "climits"},
+      {"locale.h", "clocale"}, {"math.h", "cmath"},
+      {"setjmp.h", "csetjmp"}, {"signal.h", "csignal"},
+      {"stdarg.h", "cstdarg"}, {"stddef.h", "cstddef"},
+      {"stdio.h", "cstdio"},   {"stdlib.h", "cstdlib"},
+      {"string.h", "cstring"}, {"time.h", "ctime"},
+      {"wchar.h", "cwchar"},   {"wctype.h", "cwctype"},
+  };
+  for (const auto &KeyValue : CXX98Headers)
     CStyledHeaderToCxx.insert(KeyValue);
-  }
-  // Add C++11 headers.
-  if (LangOpts.CPlusPlus11) {
-    for (const auto &KeyValue :
-         std::vector<std::pair<llvm::StringRef, std::string>>(
-             {{"fenv.h", "cfenv"},
-              {"stdint.h", "cstdint"},
-              {"inttypes.h", "cinttypes"},
-              {"tgmath.h", "ctgmath"},
-              {"uchar.h", "cuchar"}})) {
+
+  static constexpr std::pair<StringRef, StringRef> CXX11Headers[] = {
+      {"fenv.h", "cfenv"},         {"stdint.h", "cstdint"},
+      {"inttypes.h", "cinttypes"}, {"tgmath.h", "ctgmath"},
+      {"uchar.h", "cuchar"},
+  };
+  if (LangOpts.CPlusPlus11)
----------------
nicovank wrote:

```cpp
if (LangOpts.CPlusPlus11)
  CStyledHeaderToCxx.insert(std::begin(CXX11Headers), std::end(CXX11Headers));
```

https://github.com/llvm/llvm-project/pull/160967


More information about the cfe-commits mailing list