diff options
| author | Alexander Kornienko <alexfh@google.com> | 2014-10-16 15:11:54 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2014-10-16 15:11:54 +0000 |
| commit | 27f126b0064528fac915c195761a60a8ca8627bc (patch) | |
| tree | 4613eae95fe5ba8078614a8588093a2f84c28888 /clang-tools-extra | |
| parent | f445a56b61c2606378ab37c8635dcb1a3f45db8e (diff) | |
| download | bcm5719-llvm-27f126b0064528fac915c195761a60a8ca8627bc.tar.gz bcm5719-llvm-27f126b0064528fac915c195761a60a8ca8627bc.zip | |
[clang-tidy] Minor fixes for the NamespaceCommentCheck.
* Make SmallVector size enough for all groups.
* Allow trailing period in the comment.
* Fix "// anonymous namespace qqq".
llvm-svn: 219926
Diffstat (limited to 'clang-tools-extra')
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp | 10 | ||||
| -rw-r--r-- | clang-tools-extra/unittests/clang-tidy/ReadabilityChecksTest.cpp | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 3464a98b0c4..b284150dc73 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" - "namespace( +([a-zA-Z0-9_]+))? *(\\*/)?$", + "namespace( +([a-zA-Z0-9_]+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)), SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {} @@ -85,13 +85,15 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { StringRef Comment(Sources.getCharacterData(Loc), Tok.getLength()); - SmallVector<StringRef, 6> Groups; + SmallVector<StringRef, 7> Groups; if (NamespaceCommentPattern.match(Comment, &Groups)) { - StringRef NamespaceNameInComment = Groups.size() >= 6 ? Groups[5] : ""; + StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] : ""; + StringRef Anonymous = Groups.size() > 3 ? Groups[3] : ""; // Check if the namespace in the comment is the same. if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty()) || - ND->getNameAsString() == NamespaceNameInComment) { + (ND->getNameAsString() == NamespaceNameInComment && + Anonymous.empty())) { // FIXME: Maybe we need a strict mode, where we always fix namespace // comments with different format. return; diff --git a/clang-tools-extra/unittests/clang-tidy/ReadabilityChecksTest.cpp b/clang-tools-extra/unittests/clang-tidy/ReadabilityChecksTest.cpp index 847c2baf521..2d51949d5a1 100644 --- a/clang-tools-extra/unittests/clang-tidy/ReadabilityChecksTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/ReadabilityChecksTest.cpp @@ -43,6 +43,14 @@ TEST(NamespaceCommentCheckTest, CheckExistingComments) { "} // anonymous namespace", runCheckOnCode<NamespaceCommentCheck>("namespace {\n" "} // anonymous namespace")); + EXPECT_EQ("namespace {\n" + "} // Anonymous namespace.", + runCheckOnCode<NamespaceCommentCheck>("namespace {\n" + "} // Anonymous namespace.")); + EXPECT_EQ("namespace q {\n" + "} // namespace q", + runCheckOnCode<NamespaceCommentCheck>("namespace q {\n" + "} // anonymous namespace q")); EXPECT_EQ( "namespace My_NameSpace123 {\n" "} // namespace My_NameSpace123", |

