[clang-tools-extra] r217480 - [clang-tidy] Don't try to fix header guard #endif comments if there are escaped
Benjamin Kramer
benny.kra at googlemail.com
Wed Sep 10 01:48:31 PDT 2014
Author: d0k
Date: Wed Sep 10 03:48:30 2014
New Revision: 217480
URL: http://llvm.org/viewvc/llvm-project?rev=217480&view=rev
Log:
[clang-tidy] Don't try to fix header guard #endif comments if there are escaped
newlines involved.
Getting that right is just not worth it.
Modified:
clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp
clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
Modified: clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp?rev=217480&r1=217479&r2=217480&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.cpp Wed Sep 10 03:48:30 2014
@@ -143,6 +143,13 @@ public:
*EndIfLenPtr = EndIfLen;
StringRef EndIfStr(EndIfData, EndIfLen);
+
+ // Give up if there's an escaped newline.
+ size_t FindEscapedNewline = EndIfStr.find_last_not_of(' ');
+ if (FindEscapedNewline != StringRef::npos &&
+ EndIfStr[FindEscapedNewline] == '\\')
+ return false;
+
return (EndIf.isValid() && !EndIfStr.endswith("// " + HeaderGuard.str()) &&
!EndIfStr.endswith("/* " + HeaderGuard.str() + " */"));
}
Modified: clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp?rev=217480&r1=217479&r2=217480&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp Wed Sep 10 03:48:30 2014
@@ -170,6 +170,20 @@ TEST(LLVMHeaderGuardCheckTest, FixHeader
runHeaderGuardCheckWithEndif(
"#ifndef LLVM_ADT_FOO_H_\n#define LLVM_ADT_FOO_H_\n#endif // LLVM\n",
"include/llvm/ADT/foo.h"));
+
+ EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif \\ \n// "
+ "LLVM_ADT_FOO_H\n",
+ runHeaderGuardCheckWithEndif("#ifndef LLVM_ADT_FOO_H\n#define "
+ "LLVM_ADT_FOO_H\n#endif \\ \n// "
+ "LLVM_ADT_FOO_H\n",
+ "include/llvm/ADT/foo.h"));
+
+ EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif /* "
+ "LLVM_ADT_FOO_H\\ \n FOO */",
+ runHeaderGuardCheckWithEndif(
+ "#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif /* "
+ "LLVM_ADT_FOO_H\\ \n FOO */",
+ "include/llvm/ADT/foo.h"));
}
#endif
More information about the cfe-commits
mailing list