<div dir="ltr">I agree, that would be awesome. I could achieve the same functionality using some anyOf and hasName, but I considered it messier and probably less performant. Anyways, what about inline namespace support for matchesName?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 February 2016 at 12:54, 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"><div dir="ltr">I think, we need to add a `hasAnyName()` matcher that would take a list of names.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 9, 2016 at 11:20 AM, Gabor Horvath via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: xazax<br>
Date: Tue Feb 9 04:20:48 2016<br>
New Revision: 260217<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=260217&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=260217&view=rev</a><br>
Log:<br>
[clang-tidy] Make readability-container-size-empty work with inline namespaces. Fix PR25812.<br>
<br>
Modified:<br>
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp<br>
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=260217&r1=260216&r2=260217&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=260217&r1=260216&r2=260217&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp Tue Feb 9 04:20:48 2016<br>
@@ -14,23 +14,23 @@<br>
<br>
using namespace clang::ast_matchers;<br>
<br>
-static bool isContainer(llvm::StringRef ClassName) {<br>
- static const char *const ContainerNames[] = {"std::array",<br>
- "std::deque",<br>
- "std::forward_list",<br>
- "std::list",<br>
- "std::map",<br>
- "std::multimap",<br>
- "std::multiset",<br>
- "std::priority_queue",<br>
- "std::queue",<br>
- "std::set",<br>
- "std::stack",<br>
- "std::unordered_map",<br>
- "std::unordered_multimap",<br>
- "std::unordered_multiset",<br>
- "std::unordered_set",<br>
- "std::vector"};<br>
+static bool isContainerName(llvm::StringRef ClassName) {<br>
+ static const char *const ContainerNames[] = {"array",<br>
+ "deque",<br>
+ "forward_list",<br>
+ "list",<br>
+ "map",<br>
+ "multimap",<br>
+ "multiset",<br>
+ "priority_queue",<br>
+ "queue",<br>
+ "set",<br>
+ "stack",<br>
+ "unordered_map",<br>
+ "unordered_multimap",<br>
+ "unordered_multiset",<br>
+ "unordered_set",<br>
+ "vector"};<br>
return std::binary_search(std::begin(ContainerNames),<br>
std::end(ContainerNames), ClassName);<br>
}<br>
@@ -38,7 +38,10 @@ static bool isContainer(llvm::StringRef<br>
namespace clang {<br>
namespace {<br>
AST_MATCHER(NamedDecl, stlContainer) {<br>
- return isContainer(Node.getQualifiedNameAsString());<br>
+ if (!isContainerName(Node.getName()))<br>
+ return false;<br>
+<br>
+ return StringRef(Node.getQualifiedNameAsString()).startswith("std::");<br>
}<br>
} // namespace<br>
<br>
<br>
Modified: clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp?rev=260217&r1=260216&r2=260217&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp?rev=260217&r1=260216&r2=260217&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp (original)<br>
+++ clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp Tue Feb 9 04:20:48 2016<br>
@@ -2,17 +2,32 @@<br>
<br>
namespace std {<br>
template <typename T> struct vector {<br>
- vector() {}<br>
+ vector();<br>
unsigned long size() const;<br>
bool empty() const;<br>
};<br>
+<br>
+inline namespace __v2 {<br>
+template <typename T> struct set {<br>
+ set();<br>
+ unsigned long size() const;<br>
+ bool empty() const;<br>
+};<br>
+}<br>
+<br>
+<br>
}<br>
<br>
int main() {<br>
+ std::set<int> intSet;<br>
+ if (intSet.size() == 0)<br>
+ ;<br>
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]<br>
+ // CHECK-FIXES: {{^ }}if (intSet.empty()){{$}}<br>
std::vector<int> vect;<br>
if (vect.size() == 0)<br>
;<br>
- // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]<br>
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used<br>
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}<br>
if (vect.size() != 0)<br>
;<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>
</blockquote></div><br></div>