[PATCH] [clang-tidy] Add a namespace checker.

Alexander Kornienko alexfh at google.com
Wed Jul 16 04:01:25 PDT 2014


================
Comment at: clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp:38
@@ +37,3 @@
+  SourceLocation Loc = N->getLocStart();
+  if (Loc.isValid()) {
+    // Look if we're inside a header, check for common suffixes only.
----------------
Daniel Jasper wrote:
> I generally prefer early exit (but don't strongly object):
> 
>   if (!Loc.isValid())
>     return;
nit: I'd use early return instead.

================
Comment at: clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp:41
@@ +40,3 @@
+    StringRef FileName = SM->getPresumedLoc(Loc).getFilename();
+    if (FileName.endswith(".h") || FileName.endswith(".hh") ||
+        FileName.endswith(".hpp") || FileName.endswith(".hxx"))
----------------
The list of header file extensions may be a good candidate for being stored in ClangTidyOptions, so we can configure it when needed.

================
Comment at: clang-tidy/google/UsingNamespaceDirectiveCheck.cpp:30
@@ +29,3 @@
+  SourceLocation Loc = U->getLocStart();
+  if (!U->isImplicit() && Loc.isValid())
+    diag(Loc, "do not use namespace using-directives. Use using-declarations "
----------------
nit: Use early exit instead? (Especially, if we're going to implement fix-its)

================
Comment at: clang-tidy/google/UsingNamespaceDirectiveCheck.cpp:31
@@ +30,3 @@
+  if (!U->isImplicit() && Loc.isValid())
+    diag(Loc, "do not use namespace using-directives. Use using-declarations "
+              "instead.");
----------------
Further down the line we may want to suggest the list of using declarations as a replacement. Could you add a TODO?

http://reviews.llvm.org/D4523






More information about the cfe-commits mailing list