C++14 added a couple of user-defined literals in the standard library. E.g.
std::chrono_literals and std::literals::chrono_literals . Using them
requires a using directive so do not warn in google-build-using-namespace
if namespace name starts with "std::" and ends with "literals".
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
test/clang-tidy/google-namespaces.cpp | ||
---|---|---|
33 ↗ | (On Diff #98322) | s/Use/use/ . Same below. Fixing. |
clang-tidy/google/UsingNamespaceDirectiveCheck.cpp | ||
---|---|---|
43 ↗ | (On Diff #98326) | 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; } |
Comment Actions
Removed use of nested namespace definition in test (C++17) and added a couple of more namespaces with "literals" in name that check should warn for.
Comment Actions
LG with one nit. Thank you for addressing this! Do you need me to commit the patch for you?
clang-tidy/google/UsingNamespaceDirectiveCheck.cpp | ||
---|---|---|
48 ↗ | (On Diff #98914) | Please make this a static free function instead, since it doesn't need access to the check's members. |
Comment Actions
Do you need me to commit the patch for you?
Yes please. I do not have commit access.
clang-tidy/google/UsingNamespaceDirectiveCheck.cpp | ||
---|---|---|
48 ↗ | (On Diff #98914) | Done. |