#include "DanglingHandleCheck.h"
#include "FoldInitTypeCheck.h"
#include "ForwardDeclarationNamespaceCheck.h"
+#include "ForwardingReferenceOverloadCheck.h"
#include "InaccurateEraseCheck.h"
#include "IncorrectRoundingsCheck.h"
#include "IntegerDivisionCheck.h"
+#include "LambdaFunctionNameCheck.h"
+#include "MacroRepeatedSideEffectsCheck.h"
#include "MisplacedOperatorInStrlenInAllocCheck.h"
+#include "MisplacedWideningCastCheck.h"
#include "MoveForwardingReferenceCheck.h"
#include "MultipleStatementMacroCheck.h"
#include "StringConstructorCheck.h"
"bugprone-fold-init-type");
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
"bugprone-forward-declaration-namespace");
+ CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
+ "bugprone-forwarding-reference-overload");
CheckFactories.registerCheck<InaccurateEraseCheck>(
"bugprone-inaccurate-erase");
CheckFactories.registerCheck<IncorrectRoundingsCheck>(
"bugprone-incorrect-roundings");
CheckFactories.registerCheck<IntegerDivisionCheck>(
"bugprone-integer-division");
+ CheckFactories.registerCheck<LambdaFunctionNameCheck>(
+ "bugprone-lambda-function-name");
+ CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
+ "bugprone-macro-repeated-side-effects");
CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
"bugprone-misplaced-operator-in-strlen-in-alloc");
+ CheckFactories.registerCheck<MisplacedWideningCastCheck>(
+ "bugprone-misplaced-widening-cast");
CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
"bugprone-move-forwarding-reference");
CheckFactories.registerCheck<MultipleStatementMacroCheck>(
DanglingHandleCheck.cpp
FoldInitTypeCheck.cpp
ForwardDeclarationNamespaceCheck.cpp
+ ForwardingReferenceOverloadCheck.cpp
InaccurateEraseCheck.cpp
IncorrectRoundingsCheck.cpp
IntegerDivisionCheck.cpp
+ LambdaFunctionNameCheck.cpp
+ MacroRepeatedSideEffectsCheck.cpp
MisplacedOperatorInStrlenInAllocCheck.cpp
+ MisplacedWideningCastCheck.cpp
MoveForwardingReferenceCheck.cpp
MultipleStatementMacroCheck.cpp
StringConstructorCheck.cpp
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
namespace {
// Check if the given type is related to std::enable_if.
}
}
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_FORWARDING_REFERENCE_OVERLOAD_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_FORWARDING_REFERENCE_OVERLOAD_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
/// The checker looks for constructors that can act as copy or move constructors
/// through their forwarding reference parameters. If a non const lvalue
/// C++ Design, item 26.
///
/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-forwarding-reference-overload.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-forwarding-reference-overload.html
class ForwardingReferenceOverloadCheck : public ClangTidyCheck {
public:
ForwardingReferenceOverloadCheck(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_FORWARDING_REFERENCE_OVERLOAD_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
namespace {
<< PredefinedExpr::getIdentTypeName(E->getIdentType());
}
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
/// Detect when __func__ or __FUNCTION__ is being used from within a lambda. In
/// that context, those expressions expand to the name of the call operator
/// (i.e., `operator()`).
///
/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-lambda-function-name.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-lambda-function-name.html
class LambdaFunctionNameCheck : public ClangTidyCheck {
public:
struct SourceRangeLessThan {
SourceRangeSet SuppressMacroExpansions;
};
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
namespace {
class MacroRepeatedPPCallbacks : public PPCallbacks {
*this, Compiler.getPreprocessor()));
}
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MACRO_REPEATED_SIDE_EFFECTS_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MACRO_REPEATED_SIDE_EFFECTS_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROREPEATEDSIDEEFFECTSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROREPEATEDSIDEEFFECTSCHECK_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
/// Checks for repeated argument with side effects in macros.
class MacroRepeatedSideEffectsCheck : public ClangTidyCheck {
void registerPPCallbacks(CompilerInstance &Compiler) override;
};
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MACRO_REPEATED_SIDE_EFFECTS_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MACROREPEATEDSIDEEFFECTSCHECK_H
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
MisplacedWideningCastCheck::MisplacedWideningCastCheck(
StringRef Name, ClangTidyContext *Context)
<< CalcType << CastType;
}
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACED_WIDENING_CAST_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MISPLACED_WIDENING_CAST_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDWIDENINGCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDWIDENINGCASTCHECK_H
#include "../ClangTidy.h"
namespace clang {
namespace tidy {
-namespace misc {
+namespace bugprone {
/// Find casts of calculation results to bigger type. Typically from int to
/// long. If the intention of the cast is to avoid loss of precision then
// be the most common case. Enabled by default.
///
/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/misc-misplaced-widening-cast.html
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-misplaced-widening-cast.html
class MisplacedWideningCastCheck : public ClangTidyCheck {
public:
MisplacedWideningCastCheck(StringRef Name, ClangTidyContext *Context);
const bool CheckImplicitCasts;
};
-} // namespace misc
+} // namespace bugprone
} // namespace tidy
} // namespace clang
set(LLVM_LINK_COMPONENTS support)
add_clang_library(clangTidyMiscModule
- ForwardingReferenceOverloadCheck.cpp
- LambdaFunctionNameCheck.cpp
MisplacedConstCheck.cpp
UnconventionalAssignOperatorCheck.cpp
DefinitionsInHeadersCheck.cpp
MacroParenthesesCheck.cpp
- MacroRepeatedSideEffectsCheck.cpp
MiscTidyModule.cpp
- MisplacedWideningCastCheck.cpp
NewDeleteOverloadsCheck.cpp
NonCopyableObjects.cpp
RedundantExpressionCheck.cpp
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "DefinitionsInHeadersCheck.h"
-#include "ForwardingReferenceOverloadCheck.h"
-#include "LambdaFunctionNameCheck.h"
#include "MacroParenthesesCheck.h"
-#include "MacroRepeatedSideEffectsCheck.h"
#include "MisplacedConstCheck.h"
-#include "MisplacedWideningCastCheck.h"
#include "NewDeleteOverloadsCheck.h"
#include "NonCopyableObjects.h"
#include "RedundantExpressionCheck.h"
class MiscModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
- CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
- "misc-forwarding-reference-overload");
- CheckFactories.registerCheck<LambdaFunctionNameCheck>(
- "misc-lambda-function-name");
CheckFactories.registerCheck<MisplacedConstCheck>("misc-misplaced-const");
CheckFactories.registerCheck<UnconventionalAssignOperatorCheck>(
"misc-unconventional-assign-operator");
"misc-definitions-in-headers");
CheckFactories.registerCheck<MacroParenthesesCheck>(
"misc-macro-parentheses");
- CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
- "misc-macro-repeated-side-effects");
- CheckFactories.registerCheck<MisplacedWideningCastCheck>(
- "misc-misplaced-widening-cast");
CheckFactories.registerCheck<NewDeleteOverloadsCheck>(
"misc-new-delete-overloads");
CheckFactories.registerCheck<NonCopyableObjectsCheck>(
Improvements to clang-tidy
--------------------------
+- 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-lambda-function-name' check was renamed to `bugprone-lambda-function-name
+ <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-lambda-function-name.html>`_
+
+- The 'misc-macro-repeated-side-effects' check was renamed to `bugprone-macro-repeated-side-effects
+ <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-macro-repeated-side-effects.html>`_
+
+- The 'misc-forwarding-reference-overload' check was renamed to `bugprone-forwarding-reference-overload
+ <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-forwarding-reference-overload.html>`_
+
- The 'misc-incorrect-roundings' check was renamed to `bugprone-incorrect-roundings
<http://clang.llvm.org/extra/clang-tidy/checks/bugprone-incorrect-roundings.html>`_
-.. title:: clang-tidy - misc-forwarding-reference-overload
+.. title:: clang-tidy - bugprone-forwarding-reference-overload
-misc-forwarding-reference-overload
-==================================
+bugprone-forwarding-reference-overload
+======================================
The check looks for perfect forwarding constructors that can hide copy or move
constructors. If a non const lvalue reference is passed to the constructor, the
-.. title:: clang-tidy - misc-lambda-function-name
+.. title:: clang-tidy - bugprone-lambda-function-name
-misc-lambda-function-name
-=========================
+bugprone-lambda-function-name
+=============================
Checks for attempts to get the name of a function from within a lambda
expression. The name of a lambda is always something like ``operator()``, which
--- /dev/null
+.. title:: clang-tidy - bugprone-macro-repeated-side-effects
+
+bugprone-macro-repeated-side-effects
+====================================
+
+
+Checks for repeated argument with side effects in macros.
-.. title:: clang-tidy - misc-misplaced-widening-cast
+.. title:: clang-tidy - bugprone-misplaced-widening-cast
-misc-misplaced-widening-cast
-============================
+bugprone-misplaced-widening-cast
+================================
This check will warn when there is a cast of a calculation result to a bigger
type. If the intention of the cast is to avoid loss of precision then the cast
bugprone-dangling-handle
bugprone-fold-init-type
bugprone-forward-declaration-namespace
+ bugprone-forwarding-reference-overload
bugprone-inaccurate-erase
bugprone-incorrect-roundings
bugprone-integer-division
+ bugprone-lambda-function-name
+ bugprone-macro-repeated-side-effects
bugprone-misplaced-operator-in-strlen-in-alloc
+ bugprone-misplaced-widening-cast
bugprone-move-forwarding-reference
bugprone-multiple-statement-macro
bugprone-string-constructor
llvm-namespace-comment
llvm-twine-local
misc-definitions-in-headers
- misc-forwarding-reference-overload
- misc-lambda-function-name
misc-macro-parentheses
- misc-macro-repeated-side-effects
misc-misplaced-const
- misc-misplaced-widening-cast
misc-new-delete-overloads
misc-non-copyable-objects
misc-redundant-expression
+++ /dev/null
-.. title:: clang-tidy - misc-macro-repeated-side-effects
-
-misc-macro-repeated-side-effects
-================================
-
-
-Checks for repeated argument with side effects in macros.
-// RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- -std=c++14
+// RUN: %check_clang_tidy %s bugprone-forwarding-reference-overload %t -- -- -std=c++14
namespace std {
template <bool B, class T = void> struct enable_if { typedef T type; };
class Test1 {
public:
template <typename T> Test1(T &&n);
- // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload]
template <typename T> Test1(T &&n, int i = 5, ...);
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors
-// RUN: %check_clang_tidy %s misc-lambda-function-name %t
+// RUN: %check_clang_tidy %s bugprone-lambda-function-name %t
void Foo(const char* a, const char* b, int c) {}
void Positives() {
[] { __func__; }();
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [misc-lambda-function-name]
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
[] { __FUNCTION__; }();
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [misc-lambda-function-name]
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
[] { FUNC_MACRO; }();
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [misc-lambda-function-name]
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
[] { FUNCTION_MACRO; }();
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [misc-lambda-function-name]
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__FUNCTION__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
[] { EMBED_IN_ANOTHER_MACRO1; }();
- // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [misc-lambda-function-name]
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: inside a lambda, '__func__' expands to the name of the function call operator; consider capturing the name of the enclosing function explicitly [bugprone-lambda-function-name]
}
#define FUNC_MACRO_WITH_FILE_AND_LINE Foo(__func__, __FILE__, __LINE__)
-// RUN: %check_clang_tidy %s misc-macro-repeated-side-effects %t
+// RUN: %check_clang_tidy %s bugprone-macro-repeated-side-effects %t
#define badA(x,y) ((x)+((x)+(y))+(y))
void bad(int ret, int a, int b) {
ret = badA(a++, b);
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x' are repeated in macro expansion [misc-macro-repeated-side-effects]
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x' are repeated in macro expansion [bugprone-macro-repeated-side-effects]
ret = badA(++a, b);
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: side effects in the 1st macro argument 'x'
ret = badA(a--, b);
-// RUN: %check_clang_tidy %s misc-misplaced-widening-cast %t -- -config="{CheckOptions: [{key: misc-misplaced-widening-cast.CheckImplicitCasts, value: 0}]}" --
+// RUN: %check_clang_tidy %s bugprone-misplaced-widening-cast %t -- -config="{CheckOptions: [{key: bugprone-misplaced-widening-cast.CheckImplicitCasts, value: 0}]}" --
void func(long arg) {}
l = a * b;
l = (long)(a * b);
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [misc-misplaced-widening-cast]
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [bugprone-misplaced-widening-cast]
l = (long)a * b;
l = a << 8;
-// RUN: %check_clang_tidy %s misc-misplaced-widening-cast %t -- -config="{CheckOptions: [{key: misc-misplaced-widening-cast.CheckImplicitCasts, value: 1}]}" --
+// RUN: %check_clang_tidy %s bugprone-misplaced-widening-cast %t -- -config="{CheckOptions: [{key: bugprone-misplaced-widening-cast.CheckImplicitCasts, value: 1}]}" --
void func(long arg) {}
long l;
l = a * b;
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [misc-misplaced-widening-cast]
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [bugprone-misplaced-widening-cast]
l = (long)(a * b);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
l = (long)a * b;