#include "MisplacedWideningCastCheck.h"
#include "MoveForwardingReferenceCheck.h"
#include "MultipleStatementMacroCheck.h"
+#include "SizeofContainerCheck.h"
#include "SizeofExpressionCheck.h"
#include "StringConstructorCheck.h"
#include "StringIntegerAssignmentCheck.h"
"bugprone-move-forwarding-reference");
CheckFactories.registerCheck<MultipleStatementMacroCheck>(
"bugprone-multiple-statement-macro");
+ CheckFactories.registerCheck<SizeofContainerCheck>(
+ "bugprone-sizeof-container");
CheckFactories.registerCheck<SizeofExpressionCheck>(
"bugprone-sizeof-expression");
CheckFactories.registerCheck<StringConstructorCheck>(
MisplacedWideningCastCheck.cpp
MoveForwardingReferenceCheck.cpp
MultipleStatementMacroCheck.cpp
+ SizeofContainerCheck.cpp
SizeofExpressionCheck.cpp
StringConstructorCheck.cpp
StringIntegerAssignmentCheck.cpp
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
"container; did you mean .size()?");
}
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIZEOFCONTAINERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIZEOFCONTAINERCHECK_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
/// Find usages of sizeof on expressions of STL container types. Most likely the
/// user wanted to use `.size()` instead.
///
/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-sizeof-container.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-container.html
class SizeofContainerCheck : public ClangTidyCheck {
public:
SizeofContainerCheck(StringRef Name, ClangTidyContext *Context)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_SIZEOF_CONTAINER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIZEOFCONTAINERCHECK_H
NewDeleteOverloadsCheck.cpp
NonCopyableObjects.cpp
RedundantExpressionCheck.cpp
- SizeofContainerCheck.cpp
StaticAssertCheck.cpp
ThrowByValueCatchByReferenceCheck.cpp
UniqueptrResetReleaseCheck.cpp
#include "NewDeleteOverloadsCheck.h"
#include "NonCopyableObjects.h"
#include "RedundantExpressionCheck.h"
-#include "SizeofContainerCheck.h"
#include "StaticAssertCheck.h"
#include "ThrowByValueCatchByReferenceCheck.h"
#include "UnconventionalAssignOperatorCheck.h"
"misc-non-copyable-objects");
CheckFactories.registerCheck<RedundantExpressionCheck>(
"misc-redundant-expression");
- CheckFactories.registerCheck<SizeofContainerCheck>("misc-sizeof-container");
CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
CheckFactories.registerCheck<ThrowByValueCatchByReferenceCheck>(
"misc-throw-by-value-catch-by-reference");
- The 'misc-misplaced-widening-cast' check was renamed to `bugprone-misplaced-widening-cast
<http://clang.llvm.org/extra/clang-tidy/checks/bugprone-misplaced-widening-cast.html>`_
+- The 'misc-sizeof-container' check was renamed to `bugprone-sizeof-container
+ <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-container.html>`_
+
- The 'misc-sizeof-expression' check was renamed to `bugprone-sizeof-expression
<http://clang.llvm.org/extra/clang-tidy/checks/bugprone-sizeof-expression.html>`_
-.. title:: clang-tidy - misc-sizeof-container
+.. title:: clang-tidy - bugprone-sizeof-container
-misc-sizeof-container
-=====================
+bugprone-sizeof-container
+=========================
The check finds usages of ``sizeof`` on expressions of STL container types. Most
likely the user wanted to use ``.size()`` instead.
bugprone-misplaced-widening-cast
bugprone-move-forwarding-reference
bugprone-multiple-statement-macro
+ bugprone-sizeof-container
bugprone-sizeof-expression
bugprone-string-constructor
bugprone-string-integer-assignment
misc-new-delete-overloads
misc-non-copyable-objects
misc-redundant-expression
- misc-sizeof-container
misc-static-assert
misc-throw-by-value-catch-by-reference
misc-unconventional-assign-operator
-// RUN: %check_clang_tidy %s misc-sizeof-container %t -- -- -std=c++11 -target x86_64-unknown-unknown
+// RUN: %check_clang_tidy %s bugprone-sizeof-container %t -- -- -std=c++11 -target x86_64-unknown-unknown
namespace std {
std::vector<int> v;
int a = 42 + sizeof(s1);
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: sizeof() doesn't return the size of the container; did you mean .size()? [misc-sizeof-container]
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: sizeof() doesn't return the size of the container; did you mean .size()? [bugprone-sizeof-container]
a = 123 * sizeof(s2);
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: sizeof() doesn't return the size
a = 45 + sizeof(s2 + "asdf");