[clang-tools-extra] r247559 - [clang-tidy] misc-sizeof-container: whitelist std::array
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 06:55:29 PDT 2015
Author: alexfh
Date: Mon Sep 14 08:55:29 2015
New Revision: 247559
URL: http://llvm.org/viewvc/llvm-project?rev=247559&view=rev
Log:
[clang-tidy] misc-sizeof-container: whitelist std::array
Modified:
clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp?rev=247559&r1=247558&r2=247559&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SizeofContainerCheck.cpp Mon Sep 14 08:55:29 2015
@@ -36,7 +36,7 @@ void SizeofContainerCheck::registerMatch
expr(unless(isInTemplateInstantiation()),
expr(sizeOfExpr(has(expr(hasType(hasCanonicalType(hasDeclaration(
recordDecl(matchesName("^(::std::|::string)"),
- unless(hasName("::std::bitset")),
+ unless(matchesName("^::std::(bitset|array)$")),
hasMethod(methodDecl(hasName("size"), isPublic(),
isConst()))))))))))
.bind("sizeof"),
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp?rev=247559&r1=247558&r2=247559&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-container.cpp Mon Sep 14 08:55:29 2015
@@ -25,6 +25,12 @@ struct bitset {
size_t size() const;
};
+// std::array<> is, well, an array. sizeof() is reasonable for it.
+template <typename T, size_t N>
+struct array {
+ size_t size() const;
+};
+
class fake_container1 {
size_t size() const; // non-public
};
@@ -82,13 +88,15 @@ void f() {
g(s2);
g(v);
- std::fake_container1 f1;
- std::fake_container2 f2;
- std::bitset<7> bs;
-
- a = sizeof(f1);
- a = sizeof(f2);
- a = sizeof(bs);
+ std::fake_container1 fake1;
+ std::fake_container2 fake2;
+ std::bitset<7> std_bitset;
+ std::array<int, 3> std_array;
+
+ a = sizeof(fake1);
+ a = sizeof(fake2);
+ a = sizeof(std_bitset);
+ a = sizeof(std_array);
std::string arr[3];
More information about the cfe-commits
mailing list