[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.

llvm-svn: 217480
This commit is contained in:
Benjamin Kramer 2014-09-10 08:48:30 +00:00
parent eb19aea4f9
commit ad335cf690
2 changed files with 21 additions and 0 deletions

View File

@ -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() + " */"));
}

View File

@ -170,6 +170,20 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) {
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