summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-08-20 16:01:42 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-08-20 16:01:42 +0000
commit208faaaa290319b7eecab112e7922f88097c3ebe (patch)
tree70bd895cc894ef8f92e5f92bd3f000df5199cf73
parent061beab6730c9d308705333a18172bd19bd5c87c (diff)
downloadbcm5719-llvm-208faaaa290319b7eecab112e7922f88097c3ebe.tar.gz
bcm5719-llvm-208faaaa290319b7eecab112e7922f88097c3ebe.zip
[clang-tidy] Allow /**/ comments on #endifs when checking header guards.
Turning block comments into line comments just creates unecessary churn. llvm-svn: 216072
-rw-r--r--clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp3
-rw-r--r--clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp30
2 files changed, 32 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
index 327722dbbc6..133b2db2944 100644
--- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
+++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
@@ -164,7 +164,8 @@ public:
size_t EndIfLen = std::strcspn(EndIfData, "\r\n");
StringRef EndIfStr(EndIfData, EndIfLen);
- if (EndIf.isValid() && !EndIfStr.endswith("// " + HeaderGuard.str())) {
+ if (EndIf.isValid() && !EndIfStr.endswith("// " + HeaderGuard.str()) &&
+ !EndIfStr.endswith("/* " + HeaderGuard.str() + " */")) {
std::string Correct = "endif // " + HeaderGuard.str();
Check->diag(EndIf, "#endif for a header guard should reference the "
"guard macro in a comment")
diff --git a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
index 5423169caba..ce4ca641afc 100644
--- a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -93,6 +93,18 @@ static std::string runHeaderGuardCheck(StringRef Code, const Twine &Filename) {
Code, /*Errors=*/nullptr, Filename, std::string("-xc++-header"));
}
+namespace {
+struct WithEndifComment : public LLVMHeaderGuardCheck {
+ bool shouldSuggestEndifComment(StringRef Filename) override { return true; }
+};
+} // namespace
+
+static std::string runHeaderGuardCheckWithEndif(StringRef Code,
+ const Twine &Filename) {
+ return test::runCheckOnCode<WithEndifComment>(
+ Code, /*Errors=*/nullptr, Filename, std::string("-xc++-header"));
+}
+
TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) {
EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif\n",
runHeaderGuardCheck("#ifndef FOO\n#define FOO\n#endif\n",
@@ -126,6 +138,24 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) {
runHeaderGuardCheck(
"int foo;\n#ifndef FOOLOLO\n#define FOOLOLO\n#endif\n",
"include/clang/bar.h"));
+
+ EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif "
+ " // LLVM_ADT_FOO_H\n",
+ runHeaderGuardCheckWithEndif("#ifndef FOO\n#define FOO\n#endif\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",
+ runHeaderGuardCheckWithEndif("#ifndef LLVM_ADT_FOO_H\n#define "
+ "LLVM_ADT_FOO_H\n#endif // LLVM_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",
+ runHeaderGuardCheckWithEndif("#ifndef LLVM_ADT_FOO_H\n#define "
+ "LLVM_ADT_FOO_H\n"
+ "#endif /* LLVM_ADT_FOO_H */\n",
+ "include/llvm/ADT/foo.h"));
}
#endif
OpenPOWER on IntegriCloud