<div dir="ltr">Is there a particular reason that this is being tested with unittests instead of the usual lit tests? This kind of thing seems like it would be a lot more readable as a lit test.<div><br></div><div>-- Sean Silva</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 19, 2014 at 10:39 AM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alexfh<br>
Date: Mon May 19 11:39:08 2014<br>
New Revision: 209141<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=209141&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=209141&view=rev</a><br>
Log:<br>
Improved llvm-namespace-comment check.<br>
<br>
Summary:<br>
Handle various forms of existing namespace closing comments, fix<br>
existing comments with wrong namespace name, ignore short namespaces.<br>
<br>
The state of this check now seems to be enough to enable it by default to gather<br>
user feedback ;)<br>
<br>
Reviewers: klimek<br>
<br>
Reviewed By: klimek<br>
<br>
Subscribers: cfe-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D3825" target="_blank">http://reviews.llvm.org/D3825</a><br>
<br>
Added:<br>
clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp<br>
clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h<br>
clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.cpp<br>
clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.h<br>
Removed:<br>
clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.h<br>
Modified:<br>
clang-tools-extra/trunk/clang-tidy/llvm/CMakeLists.txt<br>
clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp<br>
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp<br>
clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/llvm/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/CMakeLists.txt?rev=209141&r1=209140&r2=209141&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/CMakeLists.txt?rev=209141&r1=209140&r2=209141&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/CMakeLists.txt (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/CMakeLists.txt Mon May 19 11:39:08 2014<br>
@@ -1,7 +1,9 @@<br>
set(LLVM_LINK_COMPONENTS support)<br>
<br>
add_clang_library(clangTidyLLVMModule<br>
+ IncludeOrderCheck.cpp<br>
LLVMTidyModule.cpp<br>
+ NamespaceCommentCheck.cpp<br>
<br>
LINK_LIBS<br>
clangAST<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp?rev=209141&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp?rev=209141&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp Mon May 19 11:39:08 2014<br>
@@ -0,0 +1,44 @@<br>
+//===--- IncludeOrderCheck.cpp - clang-tidy -------------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "IncludeOrderCheck.h"<br>
+#include "clang/Frontend/CompilerInstance.h"<br>
+#include "clang/Lex/PPCallbacks.h"<br>
+#include "clang/Lex/Preprocessor.h"<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+<br>
+namespace {<br>
+class IncludeOrderPPCallbacks : public PPCallbacks {<br>
+public:<br>
+ explicit IncludeOrderPPCallbacks(IncludeOrderCheck &Check) : Check(Check) {}<br>
+<br>
+ void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,<br>
+ StringRef FileName, bool IsAngled,<br>
+ CharSourceRange FilenameRange, const FileEntry *File,<br>
+ StringRef SearchPath, StringRef RelativePath,<br>
+ const Module *Imported) override {<br>
+ // FIXME: This is a dummy implementation to show how to get at preprocessor<br>
+ // information. Implement a real include order check.<br>
+ Check.diag(HashLoc, "This is an include");<br>
+ }<br>
+<br>
+private:<br>
+ IncludeOrderCheck &Check;<br>
+};<br>
+} // namespace<br>
+<br>
+void IncludeOrderCheck::registerPPCallbacks(CompilerInstance &Compiler) {<br>
+ Compiler.getPreprocessor()<br>
+ .addPPCallbacks(new IncludeOrderPPCallbacks(*this));<br>
+}<br>
+<br>
+} // namespace tidy<br>
+} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h?rev=209141&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h?rev=209141&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.h Mon May 19 11:39:08 2014<br>
@@ -0,0 +1,29 @@<br>
+//===--- IncludeOrderCheck.h - clang-tidy -----------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_INCLUDE_ORDER_CHECK_H<br>
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_INCLUDE_ORDER_CHECK_H<br>
+<br>
+#include "../ClangTidy.h"<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+<br>
+/// \brief Checks the correct order of \c #includes.<br>
+///<br>
+/// see: <a href="http://llvm.org/docs/CodingStandards.html#include-style" target="_blank">http://llvm.org/docs/CodingStandards.html#include-style</a><br>
+class IncludeOrderCheck : public ClangTidyCheck {<br>
+public:<br>
+ void registerPPCallbacks(CompilerInstance &Compiler) override;<br>
+};<br>
+<br>
+} // namespace tidy<br>
+} // namespace clang<br>
+<br>
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_INCLUDE_ORDER_CHECK_H<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp?rev=209141&r1=209140&r2=209141&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp?rev=209141&r1=209140&r2=209141&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp Mon May 19 11:39:08 2014<br>
@@ -7,75 +7,15 @@<br>
//<br>
//===----------------------------------------------------------------------===//<br>
<br>
-#include "LLVMTidyModule.h"<br>
#include "../ClangTidy.h"<br>
#include "../ClangTidyModule.h"<br>
#include "../ClangTidyModuleRegistry.h"<br>
-#include "clang/AST/ASTContext.h"<br>
-#include "clang/ASTMatchers/ASTMatchFinder.h"<br>
-#include "clang/ASTMatchers/ASTMatchers.h"<br>
-#include "clang/Frontend/CompilerInstance.h"<br>
-#include "clang/Lex/PPCallbacks.h"<br>
-#include "clang/Lex/Preprocessor.h"<br>
-#include "llvm/Support/raw_ostream.h"<br>
-<br>
-using namespace clang::ast_matchers;<br>
+#include "IncludeOrderCheck.h"<br>
+#include "NamespaceCommentCheck.h"<br>
<br>
namespace clang {<br>
namespace tidy {<br>
<br>
-void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) {<br>
- Finder->addMatcher(namespaceDecl().bind("namespace"), this);<br>
-}<br>
-<br>
-void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {<br>
- const NamespaceDecl *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace");<br>
- Token Tok;<br>
- SourceLocation Loc = ND->getRBraceLoc().getLocWithOffset(1);<br>
- while (Lexer::getRawToken(Loc, Tok, *Result.SourceManager,<br>
- Result.Context->getLangOpts())) {<br>
- Loc = Loc.getLocWithOffset(1);<br>
- }<br>
- // FIXME: Check that this namespace is "long".<br>
- if (Tok.is(tok::comment)) {<br>
- // FIXME: Check comment content.<br>
- // FIXME: Check comment placement on the same line.<br>
- return;<br>
- }<br>
- std::string Fix = " // namespace";<br>
- if (!ND->isAnonymousNamespace())<br>
- Fix = Fix.append(" ").append(ND->getNameAsString());<br>
-<br>
- diag(ND->getLocation(), "namespace not terminated with a closing comment")<br>
- << FixItHint::CreateInsertion(ND->getRBraceLoc().getLocWithOffset(1),<br>
- Fix);<br>
-}<br>
-<br>
-namespace {<br>
-class IncludeOrderPPCallbacks : public PPCallbacks {<br>
-public:<br>
- explicit IncludeOrderPPCallbacks(IncludeOrderCheck &Check) : Check(Check) {}<br>
-<br>
- void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,<br>
- StringRef FileName, bool IsAngled,<br>
- CharSourceRange FilenameRange, const FileEntry *File,<br>
- StringRef SearchPath, StringRef RelativePath,<br>
- const Module *Imported) override {<br>
- // FIXME: This is a dummy implementation to show how to get at preprocessor<br>
- // information. Implement a real include order check.<br>
- Check.diag(HashLoc, "This is an include");<br>
- }<br>
-<br>
-private:<br>
- IncludeOrderCheck &Check;<br>
-};<br>
-} // namespace<br>
-<br>
-void IncludeOrderCheck::registerPPCallbacks(CompilerInstance &Compiler) {<br>
- Compiler.getPreprocessor()<br>
- .addPPCallbacks(new IncludeOrderPPCallbacks(*this));<br>
-}<br>
-<br>
class LLVMModule : public ClangTidyModule {<br>
public:<br>
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {<br>
<br>
Removed: clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.h?rev=209140&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.h?rev=209140&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.h (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.h (removed)<br>
@@ -1,38 +0,0 @@<br>
-//===--- LLVMTidyModule.h - clang-tidy --------------------------*- C++ -*-===//<br>
-//<br>
-// The LLVM Compiler Infrastructure<br>
-//<br>
-// This file is distributed under the University of Illinois Open Source<br>
-// License. See LICENSE.TXT for details.<br>
-//<br>
-//===----------------------------------------------------------------------===//<br>
-<br>
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_LLVM_TIDY_MODULE_H<br>
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_LLVM_TIDY_MODULE_H<br>
-<br>
-#include "../ClangTidy.h"<br>
-<br>
-namespace clang {<br>
-namespace tidy {<br>
-<br>
-/// \brief Checks the correct order of \c #includes.<br>
-///<br>
-/// see: <a href="http://llvm.org/docs/CodingStandards.html#include-style
-class" target="_blank">http://llvm.org/docs/CodingStandards.html#include-style<br>
-class</a> IncludeOrderCheck : public ClangTidyCheck {<br>
-public:<br>
- void registerPPCallbacks(CompilerInstance &Compiler) override;<br>
-};<br>
-<br>
-/// \brief Checks that long namespaces have a closing comment.<br>
-///<br>
-/// see: <a href="http://llvm.org/docs/CodingStandards.html#namespace-indentation
-class" target="_blank">http://llvm.org/docs/CodingStandards.html#namespace-indentation<br>
-class</a> NamespaceCommentCheck : public ClangTidyCheck {<br>
-public:<br>
- void registerMatchers(ast_matchers::MatchFinder *Finder) override;<br>
- void check(const ast_matchers::MatchFinder::MatchResult &Result) override;<br>
-};<br>
-<br>
-} // namespace tidy<br>
-} // namespace clang<br>
-<br>
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_TIDY_LLVM_MODULE_H<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.cpp?rev=209141&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.cpp?rev=209141&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.cpp (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.cpp Mon May 19 11:39:08 2014<br>
@@ -0,0 +1,115 @@<br>
+//===--- NamespaceCommentCheck.cpp - clang-tidy ---------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "NamespaceCommentCheck.h"<br>
+#include "clang/AST/ASTContext.h"<br>
+#include "clang/ASTMatchers/ASTMatchers.h"<br>
+#include "clang/Lex/Lexer.h"<br>
+<br>
+<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+using namespace clang::ast_matchers;<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+<br>
+NamespaceCommentCheck::NamespaceCommentCheck()<br>
+ : NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"<br>
+ "namespace( +([a-zA-Z0-9_]+))? *(\\*/)?$",<br>
+ llvm::Regex::IgnoreCase),<br>
+ ShortNamespaceLines(1) {}<br>
+<br>
+void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) {<br>
+ Finder->addMatcher(namespaceDecl().bind("namespace"), this);<br>
+}<br>
+<br>
+bool locationsInSameFile(const SourceManager &Sources, SourceLocation Loc1,<br>
+ SourceLocation Loc2) {<br>
+ return Loc1.isFileID() && Loc2.isFileID() &&<br>
+ Sources.getFileID(Loc1) == Sources.getFileID(Loc2);<br>
+}<br>
+<br>
+std::string getNamespaceComment(const NamespaceDecl *ND, bool InsertLineBreak) {<br>
+ std::string Fix = "// namespace";<br>
+ if (!ND->isAnonymousNamespace())<br>
+ Fix.append(" ").append(ND->getNameAsString());<br>
+ if (InsertLineBreak)<br>
+ Fix.append("\n");<br>
+ return Fix;<br>
+}<br>
+<br>
+void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {<br>
+ const NamespaceDecl *ND = Result.Nodes.getNodeAs<NamespaceDecl>("namespace");<br>
+ const SourceManager &Sources = *Result.SourceManager;<br>
+<br>
+ if (!locationsInSameFile(Sources, ND->getLocStart(), ND->getRBraceLoc()))<br>
+ return;<br>
+<br>
+ // Don't require closing comments for namespaces spanning less than certain<br>
+ // number of lines.<br>
+ unsigned StartLine = Sources.getSpellingLineNumber(ND->getLocStart());<br>
+ unsigned EndLine = Sources.getSpellingLineNumber(ND->getRBraceLoc());<br>
+ if (EndLine - StartLine + 1 <= ShortNamespaceLines)<br>
+ return;<br>
+<br>
+ // Find next token after the namespace closing brace.<br>
+ SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);<br>
+ SourceLocation Loc = AfterRBrace;<br>
+ Token Tok;<br>
+ // Skip whitespace until we find the next token.<br>
+ while (Lexer::getRawToken(Loc, Tok, Sources, Result.Context->getLangOpts())) {<br>
+ Loc = Loc.getLocWithOffset(1);<br>
+ }<br>
+ if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))<br>
+ return;<br>
+<br>
+ bool NextTokenIsOnSameLine = Sources.getSpellingLineNumber(Loc) == EndLine;<br>
+ bool NeedLineBreak = NextTokenIsOnSameLine && Tok.isNot(tok::eof);<br>
+<br>
+ // Try to find existing namespace closing comment on the same line.<br>
+ if (Tok.is(tok::comment) && NextTokenIsOnSameLine) {<br>
+ StringRef Comment(Sources.getCharacterData(Loc), Tok.getLength());<br>
+ SmallVector<StringRef, 6> Groups;<br>
+ if (NamespaceCommentPattern.match(Comment, &Groups)) {<br>
+ StringRef NamespaceNameInComment = Groups.size() >= 6 ? Groups[5] : "";<br>
+<br>
+ // Check if the namespace in the comment is the same.<br>
+ if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty()) ||<br>
+ ND->getNameAsString() == NamespaceNameInComment) {<br>
+ // FIXME: Maybe we need a strict mode, where we always fix namespace<br>
+ // comments with different format.<br>
+ return;<br>
+ }<br>
+<br>
+ // Otherwise we need to fix the comment.<br>
+ NeedLineBreak = Comment.startswith("/*");<br>
+ CharSourceRange OldCommentRange = CharSourceRange::getCharRange(<br>
+ SourceRange(Loc, Loc.getLocWithOffset(Tok.getLength())));<br>
+ diag(Loc, "namespace closing comment refers to a wrong namespace '%0'")<br>
+ << NamespaceNameInComment<br>
+ << FixItHint::CreateReplacement(<br>
+ OldCommentRange, getNamespaceComment(ND, NeedLineBreak));<br>
+ return;<br>
+ }<br>
+<br>
+ // This is not a recognized form of a namespace closing comment.<br>
+ // Leave line comment on the same line. Move block comment to the next line,<br>
+ // as it can be multi-line or there may be other tokens behind it.<br>
+ if (Comment.startswith("//"))<br>
+ NeedLineBreak = false;<br>
+ }<br>
+<br>
+ diag(ND->getLocation(), "namespace not terminated with a closing comment")<br>
+ << FixItHint::CreateInsertion(<br>
+ AfterRBrace, " " + getNamespaceComment(ND, NeedLineBreak));<br>
+}<br>
+<br>
+} // namespace tidy<br>
+} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.h?rev=209141&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.h?rev=209141&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.h (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/llvm/NamespaceCommentCheck.h Mon May 19 11:39:08 2014<br>
@@ -0,0 +1,36 @@<br>
+//===--- NamespaceCommentCheck.h - clang-tidy -------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_NAMESPACE_COMMENT_CHECK_H<br>
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_NAMESPACE_COMMENT_CHECK_H<br>
+<br>
+#include "../ClangTidy.h"<br>
+#include "llvm/Support/Regex.h"<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+<br>
+/// \brief Checks that long namespaces have a closing comment.<br>
+///<br>
+/// see: <a href="http://llvm.org/docs/CodingStandards.html#namespace-indentation" target="_blank">http://llvm.org/docs/CodingStandards.html#namespace-indentation</a><br>
+class NamespaceCommentCheck : public ClangTidyCheck {<br>
+public:<br>
+ NamespaceCommentCheck();<br>
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;<br>
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;<br>
+<br>
+private:<br>
+ llvm::Regex NamespaceCommentPattern;<br>
+ const unsigned ShortNamespaceLines;<br>
+};<br>
+<br>
+} // namespace tidy<br>
+} // namespace clang<br>
+<br>
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_NAMESPACE_COMMENT_CHECK_H<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=209141&r1=209140&r2=209141&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=209141&r1=209140&r2=209141&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon May 19 11:39:08 2014<br>
@@ -31,7 +31,6 @@ const char DefaultChecks[] =<br>
"*," // Enable all checks, except these:<br>
"-clang-analyzer-alpha*," // Too many false positives.<br>
"-llvm-include-order," // Not implemented yet.<br>
- "-llvm-namespace-comment," // Not complete.<br>
"-google-*,"; // Doesn't apply to LLVM.<br>
static cl::opt<std::string><br>
Checks("checks", cl::desc("Comma-separated list of globs with optional '-'\n"<br>
<br>
Modified: clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp?rev=209141&r1=209140&r2=209141&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp?rev=209141&r1=209140&r2=209141&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp (original)<br>
+++ clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp Mon May 19 11:39:08 2014<br>
@@ -1,5 +1,6 @@<br>
#include "ClangTidyTest.h"<br>
-#include "llvm/LLVMTidyModule.h"<br>
+#include "llvm/IncludeOrderCheck.h"<br>
+#include "llvm/NamespaceCommentCheck.h"<br>
#include "gtest/gtest.h"<br>
<br>
namespace clang {<br>
@@ -9,6 +10,79 @@ namespace test {<br>
TEST(NamespaceCommentCheckTest, Basic) {<br>
EXPECT_EQ("namespace i {\n} // namespace i",<br>
runCheckOnCode<NamespaceCommentCheck>("namespace i {\n}"));<br>
+ EXPECT_EQ("namespace {\n} // namespace",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n}"));<br>
+ EXPECT_EQ(<br>
+ "namespace i { namespace j {\n} // namespace j\n } // namespace i",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace i { namespace j {\n} }"));<br>
+}<br>
+<br>
+TEST(NamespaceCommentCheckTest, SingleLineNamespaces) {<br>
+ EXPECT_EQ(<br>
+ "namespace i { namespace j { } }",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace i { namespace j { } }"));<br>
+}<br>
+<br>
+TEST(NamespaceCommentCheckTest, CheckExistingComments) {<br>
+ EXPECT_EQ("namespace i { namespace j {\n"<br>
+ "} /* namespace j */ } // namespace i\n"<br>
+ " /* random comment */",<br>
+ runCheckOnCode<NamespaceCommentCheck>(<br>
+ "namespace i { namespace j {\n"<br>
+ "} /* namespace j */ } /* random comment */"));<br>
+ EXPECT_EQ("namespace {\n"<br>
+ "} // namespace",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n"<br>
+ "} // namespace"));<br>
+ EXPECT_EQ("namespace {\n"<br>
+ "} //namespace",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n"<br>
+ "} //namespace"));<br>
+ EXPECT_EQ("namespace {\n"<br>
+ "} // anonymous namespace",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n"<br>
+ "} // anonymous namespace"));<br>
+ EXPECT_EQ(<br>
+ "namespace My_NameSpace123 {\n"<br>
+ "} // namespace My_NameSpace123",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace My_NameSpace123 {\n"<br>
+ "} // namespace My_NameSpace123"));<br>
+ EXPECT_EQ(<br>
+ "namespace My_NameSpace123 {\n"<br>
+ "} //namespace My_NameSpace123",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace My_NameSpace123 {\n"<br>
+ "} //namespace My_NameSpace123"));<br>
+ EXPECT_EQ("namespace My_NameSpace123 {\n"<br>
+ "} // end namespace My_NameSpace123",<br>
+ runCheckOnCode<NamespaceCommentCheck>(<br>
+ "namespace My_NameSpace123 {\n"<br>
+ "} // end namespace My_NameSpace123"));<br>
+ // Understand comments only on the same line.<br>
+ EXPECT_EQ("namespace {\n"<br>
+ "} // namespace\n"<br>
+ "// namespace",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n"<br>
+ "}\n"<br>
+ "// namespace"));<br>
+ // Leave unknown comments.<br>
+ EXPECT_EQ("namespace {\n"<br>
+ "} // namespace // random text",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n"<br>
+ "} // random text"));<br>
+}<br>
+<br>
+TEST(NamespaceCommentCheckTest, FixWrongComments) {<br>
+ EXPECT_EQ("namespace i { namespace jJ0_ {\n"<br>
+ "} // namespace jJ0_\n"<br>
+ " } // namespace i\n"<br>
+ " /* random comment */",<br>
+ runCheckOnCode<NamespaceCommentCheck>(<br>
+ "namespace i { namespace jJ0_ {\n"<br>
+ "} /* namespace qqq */ } /* random comment */"));<br>
+ EXPECT_EQ("namespace {\n"<br>
+ "} // namespace",<br>
+ runCheckOnCode<NamespaceCommentCheck>("namespace {\n"<br>
+ "} // namespace asdf"));<br>
}<br>
<br>
} // namespace test<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>