[clang-tools-extra] r260217 - [clang-tidy] Make readability-container-size-empty work with inline namespaces. Fix PR25812.
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 9 02:20:50 PST 2016
Author: xazax
Date: Tue Feb 9 04:20:48 2016
New Revision: 260217
URL: http://llvm.org/viewvc/llvm-project?rev=260217&view=rev
Log:
[clang-tidy] Make readability-container-size-empty work with inline namespaces. Fix PR25812.
Modified:
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=260217&r1=260216&r2=260217&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp Tue Feb 9 04:20:48 2016
@@ -14,23 +14,23 @@
using namespace clang::ast_matchers;
-static bool isContainer(llvm::StringRef ClassName) {
- static const char *const ContainerNames[] = {"std::array",
- "std::deque",
- "std::forward_list",
- "std::list",
- "std::map",
- "std::multimap",
- "std::multiset",
- "std::priority_queue",
- "std::queue",
- "std::set",
- "std::stack",
- "std::unordered_map",
- "std::unordered_multimap",
- "std::unordered_multiset",
- "std::unordered_set",
- "std::vector"};
+static bool isContainerName(llvm::StringRef ClassName) {
+ static const char *const ContainerNames[] = {"array",
+ "deque",
+ "forward_list",
+ "list",
+ "map",
+ "multimap",
+ "multiset",
+ "priority_queue",
+ "queue",
+ "set",
+ "stack",
+ "unordered_map",
+ "unordered_multimap",
+ "unordered_multiset",
+ "unordered_set",
+ "vector"};
return std::binary_search(std::begin(ContainerNames),
std::end(ContainerNames), ClassName);
}
@@ -38,7 +38,10 @@ static bool isContainer(llvm::StringRef
namespace clang {
namespace {
AST_MATCHER(NamedDecl, stlContainer) {
- return isContainer(Node.getQualifiedNameAsString());
+ if (!isContainerName(Node.getName()))
+ return false;
+
+ return StringRef(Node.getQualifiedNameAsString()).startswith("std::");
}
} // namespace
Modified: clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
URL: 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
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp Tue Feb 9 04:20:48 2016
@@ -2,17 +2,32 @@
namespace std {
template <typename T> struct vector {
- vector() {}
+ vector();
unsigned long size() const;
bool empty() const;
};
+
+inline namespace __v2 {
+template <typename T> struct set {
+ set();
+ unsigned long size() const;
+ bool empty() const;
+};
+}
+
+
}
int main() {
+ std::set<int> intSet;
+ if (intSet.size() == 0)
+ ;
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
+ // CHECK-FIXES: {{^ }}if (intSet.empty()){{$}}
std::vector<int> vect;
if (vect.size() == 0)
;
- // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
+ // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
// CHECK-FIXES: {{^ }}if (vect.empty()){{$}}
if (vect.size() != 0)
;
More information about the cfe-commits
mailing list