hokein created this revision. Herald added subscribers: xazax.hun, JDevlieghere.
https://reviews.llvm.org/D35787 Files: clang-tidy/performance/InefficientVectorOperationCheck.cpp test/clang-tidy/performance-inefficient-vector-operation.cpp Index: test/clang-tidy/performance-inefficient-vector-operation.cpp =================================================================== --- test/clang-tidy/performance-inefficient-vector-operation.cpp +++ test/clang-tidy/performance-inefficient-vector-operation.cpp @@ -274,4 +274,12 @@ z12.push_back(e); } } + { + std::vector<bool> z14; + // std::vector<bool> will be ignored as STL provides a possibly + // space-efficient specilaization of std::vector for the type "bool". + for (int i = 0; i < 10; ++i) { + z14.push_back(true); + } + } } Index: clang-tidy/performance/InefficientVectorOperationCheck.cpp =================================================================== --- clang-tidy/performance/InefficientVectorOperationCheck.cpp +++ clang-tidy/performance/InefficientVectorOperationCheck.cpp @@ -73,8 +73,13 @@ } void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) { - const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector<StringRef, 5>( - VectorLikeClasses.begin(), VectorLikeClasses.end()))); + const auto VectorDecl = classTemplateSpecializationDecl( + hasAnyName(SmallVector<StringRef, 5>(VectorLikeClasses.begin(), + VectorLikeClasses.end())), + // Exclude std::vector<bool>: STL provides a specilaization of std::vector + // for the type "bool", which may be optimized for space efficiency (e.g. + // each element occupies a single bit instead of sizeof(bool) bytes). + unless(hasTemplateArgument(0, refersToType(booleanType())))); const auto VectorDefaultConstructorCall = cxxConstructExpr( hasType(VectorDecl), hasDeclaration(cxxConstructorDecl(isDefaultConstructor())));
Index: test/clang-tidy/performance-inefficient-vector-operation.cpp =================================================================== --- test/clang-tidy/performance-inefficient-vector-operation.cpp +++ test/clang-tidy/performance-inefficient-vector-operation.cpp @@ -274,4 +274,12 @@ z12.push_back(e); } } + { + std::vector<bool> z14; + // std::vector<bool> will be ignored as STL provides a possibly + // space-efficient specilaization of std::vector for the type "bool". + for (int i = 0; i < 10; ++i) { + z14.push_back(true); + } + } } Index: clang-tidy/performance/InefficientVectorOperationCheck.cpp =================================================================== --- clang-tidy/performance/InefficientVectorOperationCheck.cpp +++ clang-tidy/performance/InefficientVectorOperationCheck.cpp @@ -73,8 +73,13 @@ } void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) { - const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector<StringRef, 5>( - VectorLikeClasses.begin(), VectorLikeClasses.end()))); + const auto VectorDecl = classTemplateSpecializationDecl( + hasAnyName(SmallVector<StringRef, 5>(VectorLikeClasses.begin(), + VectorLikeClasses.end())), + // Exclude std::vector<bool>: STL provides a specilaization of std::vector + // for the type "bool", which may be optimized for space efficiency (e.g. + // each element occupies a single bit instead of sizeof(bool) bytes). + unless(hasTemplateArgument(0, refersToType(booleanType())))); const auto VectorDefaultConstructorCall = cxxConstructExpr( hasType(VectorDecl), hasDeclaration(cxxConstructorDecl(isDefaultConstructor())));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits