[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
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 3464a98..b284150 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -23,7 +23,7 @@
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 @@
// 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;