[PATCH] D115715: [clang-tidy] Fix llvm-header-guard for Windows paths containing drive letter (e.g. C:).

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 14 01:53:03 PST 2021


curdeius created this revision.
curdeius added reviewers: aaron.ballman, hokein, bkramer, salman-javed-nz, alexfh.
Herald added subscribers: carlosgalvezp, xazax.hun.
curdeius requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixes http://llvm.org/PR52682.

The previous fix (https://reviews.llvm.org/rGb4f6f1c) escaped backslashes, but didn't cover colons.

So the check, for a file called e.g. "C:\test\test.h" would suggest the guard `C:_TEST_TEST_H` being an invalid name due to the presence of the colon.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115715

Files:
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
  clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp


Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===================================================================
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -267,6 +267,15 @@
             runHeaderGuardCheck(
                 "", "\\\\?\\C:\\llvm-project\\clang-tools-extra\\clangd\\foo.h",
                 StringRef("header is missing header guard")));
+
+  EXPECT_EQ("#ifndef C__TEST_FOO_H\n"
+            "#define C__TEST_FOO_H\n"
+            "\n"
+            "\n"
+            "#endif\n",
+            runHeaderGuardCheck("", "c:\\test\\foo.h",
+                                StringRef("header is missing header guard")));
+
 #endif
 }
 
Index: clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
+++ clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
@@ -54,6 +54,7 @@
   std::replace(Guard.begin(), Guard.end(), '/', '_');
   std::replace(Guard.begin(), Guard.end(), '.', '_');
   std::replace(Guard.begin(), Guard.end(), '-', '_');
+  std::replace(Guard.begin(), Guard.end(), ':', '_');
 
   // The prevalent style in clang is LLVM_CLANG_FOO_BAR_H
   if (StringRef(Guard).startswith("clang"))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115715.394188.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211214/930d1a38/attachment.bin>


More information about the cfe-commits mailing list