forked from OSchip/llvm-project
[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:
parent
eb19aea4f9
commit
ad335cf690
|
@ -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() + " */"));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue