[PATCH] D33010: Make google-build-using-namespace skip std::.*literals

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 11 08:31:39 PDT 2017


alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.


================
Comment at: clang-tidy/google/UsingNamespaceDirectiveCheck.cpp:43
+  if (StandardLiteralsNamespaceRE.match(
+          U->getNominatedNamespace()->getQualifiedNameAsString())) {
+    // Do not warn if name matches std::.*literals. User-defined literals in
----------------
`getQualifiedNameAsString()` is pretty expensive, since it allocates a string and reconstructs the qualified name by going up all declaration contexts. Instead, consider checking the names directly, something like this:

  const NamespaceDecl *NS = U->getNominatedNamespace();
  if (NS->getName().ends_with("literals")) {
    const auto *Parent = dyn_cast_or_null<NamespaceDecl>(NS->getParent());
    if (Parent && (Parent->isStdNamespace() || (Parent->getName() == "literals" && Parent->getParent() && Parent->getParent()->isStdNamespace())))
      return;
  }
  


https://reviews.llvm.org/D33010





More information about the cfe-commits mailing list