mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-29 00:21:14 +00:00
[clang-tidy] Move more checks from misc- to performance-
Summary: rename_check.py misc-move-const-arg performance-move-const-arg rename_check.py misc-noexcept-move-constructor performance-noexcept-move-constructor Reviewers: hokein, xazax.hun Reviewed By: xazax.hun Subscribers: rnkovacs, klimek, mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40507 llvm-svn: 319183
This commit is contained in:
parent
14230e02ff
commit
1bfcba8cea
@ -17,6 +17,7 @@ add_clang_library(clangTidyHICPPModule
|
||||
clangTidyGoogleModule
|
||||
clangTidyMiscModule
|
||||
clangTidyModernizeModule
|
||||
clangTidyPerformanceModule
|
||||
clangTidyReadabilityModule
|
||||
clangTidyUtils
|
||||
)
|
||||
|
@ -18,9 +18,7 @@
|
||||
#include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h"
|
||||
#include "../google/DefaultArgumentsCheck.h"
|
||||
#include "../google/ExplicitConstructorCheck.h"
|
||||
#include "../misc/MoveConstantArgumentCheck.h"
|
||||
#include "../misc/NewDeleteOverloadsCheck.h"
|
||||
#include "../misc/NoexceptMoveConstructorCheck.h"
|
||||
#include "../misc/StaticAssertCheck.h"
|
||||
#include "../misc/UndelegatedConstructor.h"
|
||||
#include "../modernize/DeprecatedHeadersCheck.h"
|
||||
@ -31,6 +29,8 @@
|
||||
#include "../modernize/UseNoexceptCheck.h"
|
||||
#include "../modernize/UseNullptrCheck.h"
|
||||
#include "../modernize/UseOverrideCheck.h"
|
||||
#include "../performance/MoveConstArgCheck.h"
|
||||
#include "../performance/NoexceptMoveConstructorCheck.h"
|
||||
#include "../readability/BracesAroundStatementsCheck.h"
|
||||
#include "../readability/FunctionSizeCheck.h"
|
||||
#include "../readability/IdentifierNamingCheck.h"
|
||||
@ -63,11 +63,11 @@ public:
|
||||
"hicpp-invalid-access-moved");
|
||||
CheckFactories.registerCheck<cppcoreguidelines::ProTypeMemberInitCheck>(
|
||||
"hicpp-member-init");
|
||||
CheckFactories.registerCheck<misc::MoveConstantArgumentCheck>(
|
||||
CheckFactories.registerCheck<performance::MoveConstArgCheck>(
|
||||
"hicpp-move-const-arg");
|
||||
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
|
||||
"hicpp-new-delete-operators");
|
||||
CheckFactories.registerCheck<misc::NoexceptMoveConstructorCheck>(
|
||||
CheckFactories.registerCheck<performance::NoexceptMoveConstructorCheck>(
|
||||
"hicpp-noexcept-move");
|
||||
CheckFactories
|
||||
.registerCheck<cppcoreguidelines::ProBoundsArrayToPointerDecayCheck>(
|
||||
|
@ -11,9 +11,7 @@ add_clang_library(clangTidyMiscModule
|
||||
MacroRepeatedSideEffectsCheck.cpp
|
||||
MiscTidyModule.cpp
|
||||
MisplacedWideningCastCheck.cpp
|
||||
MoveConstantArgumentCheck.cpp
|
||||
NewDeleteOverloadsCheck.cpp
|
||||
NoexceptMoveConstructorCheck.cpp
|
||||
NonCopyableObjects.cpp
|
||||
RedundantExpressionCheck.cpp
|
||||
SizeofContainerCheck.cpp
|
||||
|
@ -18,9 +18,7 @@
|
||||
#include "MacroRepeatedSideEffectsCheck.h"
|
||||
#include "MisplacedConstCheck.h"
|
||||
#include "MisplacedWideningCastCheck.h"
|
||||
#include "MoveConstantArgumentCheck.h"
|
||||
#include "NewDeleteOverloadsCheck.h"
|
||||
#include "NoexceptMoveConstructorCheck.h"
|
||||
#include "NonCopyableObjects.h"
|
||||
#include "RedundantExpressionCheck.h"
|
||||
#include "SizeofContainerCheck.h"
|
||||
@ -67,12 +65,8 @@ public:
|
||||
"misc-macro-repeated-side-effects");
|
||||
CheckFactories.registerCheck<MisplacedWideningCastCheck>(
|
||||
"misc-misplaced-widening-cast");
|
||||
CheckFactories.registerCheck<MoveConstantArgumentCheck>(
|
||||
"misc-move-const-arg");
|
||||
CheckFactories.registerCheck<NewDeleteOverloadsCheck>(
|
||||
"misc-new-delete-overloads");
|
||||
CheckFactories.registerCheck<NoexceptMoveConstructorCheck>(
|
||||
"misc-noexcept-move-constructor");
|
||||
CheckFactories.registerCheck<NonCopyableObjectsCheck>(
|
||||
"misc-non-copyable-objects");
|
||||
CheckFactories.registerCheck<RedundantExpressionCheck>(
|
||||
|
@ -187,7 +187,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
return;
|
||||
|
||||
// If the parameter is trivial to copy, don't move it. Moving a trivivally
|
||||
// copyable type will cause a problem with misc-move-const-arg
|
||||
// copyable type will cause a problem with performance-move-const-arg
|
||||
if (ParamDecl->getType().getNonReferenceType().isTriviallyCopyableType(
|
||||
*Result.Context))
|
||||
return;
|
||||
|
@ -7,7 +7,9 @@ add_clang_library(clangTidyPerformanceModule
|
||||
InefficientAlgorithmCheck.cpp
|
||||
InefficientStringConcatenationCheck.cpp
|
||||
InefficientVectorOperationCheck.cpp
|
||||
MoveConstArgCheck.cpp
|
||||
MoveConstructorInitCheck.cpp
|
||||
NoexceptMoveConstructorCheck.cpp
|
||||
PerformanceTidyModule.cpp
|
||||
TypePromotionInMathFnCheck.cpp
|
||||
UnnecessaryCopyInitialization.cpp
|
||||
|
@ -1,4 +1,4 @@
|
||||
//===--- MoveConstantArgumentCheck.cpp - clang-tidy -----------------------===//
|
||||
//===--- MoveConstArgCheck.cpp - clang-tidy -----------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MoveConstantArgumentCheck.h"
|
||||
#include "MoveConstArgCheck.h"
|
||||
|
||||
#include "clang/Lex/Lexer.h"
|
||||
|
||||
@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace performance {
|
||||
|
||||
static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag,
|
||||
const SourceManager &SM,
|
||||
@ -36,12 +36,11 @@ static void ReplaceCallWithArg(const CallExpr *Call, DiagnosticBuilder &Diag,
|
||||
}
|
||||
}
|
||||
|
||||
void MoveConstantArgumentCheck::storeOptions(
|
||||
ClangTidyOptions::OptionMap &Opts) {
|
||||
void MoveConstArgCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
|
||||
Options.store(Opts, "CheckTriviallyCopyableMove", CheckTriviallyCopyableMove);
|
||||
}
|
||||
|
||||
void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) {
|
||||
void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) {
|
||||
if (!getLangOpts().CPlusPlus)
|
||||
return;
|
||||
|
||||
@ -60,7 +59,7 @@ void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) {
|
||||
this);
|
||||
}
|
||||
|
||||
void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
const auto *CallMove = Result.Nodes.getNodeAs<CallExpr>("call-move");
|
||||
const auto *ReceivingExpr = Result.Nodes.getNodeAs<Expr>("receiving-expr");
|
||||
const Expr *Arg = CallMove->getArg(0);
|
||||
@ -117,6 +116,6 @@ void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace misc
|
||||
} // namespace performance
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
@ -1,4 +1,4 @@
|
||||
//===--- MoveConstantArgumentCheck.h - clang-tidy -------------------------===//
|
||||
//===--- MoveConstArgCheck.h - clang-tidy -------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace performance {
|
||||
|
||||
/// Find casts of calculation results to bigger type. Typically from int to
|
||||
///
|
||||
@ -22,9 +22,9 @@ namespace misc {
|
||||
///
|
||||
/// - `CheckTriviallyCopyableMove`: Whether to check for trivially-copyable
|
||||
// types as their objects are not moved but copied. Enabled by default.
|
||||
class MoveConstantArgumentCheck : public ClangTidyCheck {
|
||||
class MoveConstArgCheck : public ClangTidyCheck {
|
||||
public:
|
||||
MoveConstantArgumentCheck(StringRef Name, ClangTidyContext *Context)
|
||||
MoveConstArgCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context),
|
||||
CheckTriviallyCopyableMove(
|
||||
Options.get("CheckTriviallyCopyableMove", true)) {}
|
||||
@ -36,7 +36,7 @@ private:
|
||||
const bool CheckTriviallyCopyableMove;
|
||||
};
|
||||
|
||||
} // namespace misc
|
||||
} // namespace performance
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
@ -15,7 +15,7 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace performance {
|
||||
|
||||
void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
|
||||
// Only register the matchers for C++11; the functionality currently does not
|
||||
@ -48,30 +48,30 @@ void NoexceptMoveConstructorCheck::check(
|
||||
return;
|
||||
|
||||
switch (ProtoType->getNoexceptSpec(*Result.Context)) {
|
||||
case FunctionProtoType::NR_NoNoexcept:
|
||||
diag(Decl->getLocation(), "move %0s should be marked noexcept")
|
||||
case FunctionProtoType::NR_NoNoexcept:
|
||||
diag(Decl->getLocation(), "move %0s should be marked noexcept")
|
||||
<< MethodType;
|
||||
// FIXME: Add a fixit.
|
||||
break;
|
||||
case FunctionProtoType::NR_Throw:
|
||||
// Don't complain about nothrow(false), but complain on nothrow(expr)
|
||||
// where expr evaluates to false.
|
||||
if (const Expr *E = ProtoType->getNoexceptExpr()) {
|
||||
if (isa<CXXBoolLiteralExpr>(E))
|
||||
break;
|
||||
diag(E->getExprLoc(),
|
||||
"noexcept specifier on the move %0 evaluates to 'false'")
|
||||
<< MethodType;
|
||||
// FIXME: Add a fixit.
|
||||
break;
|
||||
case FunctionProtoType::NR_Throw:
|
||||
// Don't complain about nothrow(false), but complain on nothrow(expr)
|
||||
// where expr evaluates to false.
|
||||
if (const Expr *E = ProtoType->getNoexceptExpr()) {
|
||||
if (isa<CXXBoolLiteralExpr>(E))
|
||||
break;
|
||||
diag(E->getExprLoc(),
|
||||
"noexcept specifier on the move %0 evaluates to 'false'")
|
||||
<< MethodType;
|
||||
}
|
||||
break;
|
||||
case FunctionProtoType::NR_Nothrow:
|
||||
case FunctionProtoType::NR_Dependent:
|
||||
case FunctionProtoType::NR_BadNoexcept:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case FunctionProtoType::NR_Nothrow:
|
||||
case FunctionProtoType::NR_Dependent:
|
||||
case FunctionProtoType::NR_BadNoexcept:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace misc
|
||||
} // namespace performance
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
@ -7,14 +7,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H
|
||||
|
||||
#include "../ClangTidy.h"
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace misc {
|
||||
namespace performance {
|
||||
|
||||
/// The check flags user-defined move constructors and assignment operators not
|
||||
/// marked with `noexcept` or marked with `noexcept(expr)` where `expr`
|
||||
@ -31,8 +31,8 @@ public:
|
||||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
||||
};
|
||||
|
||||
} // namespace misc
|
||||
} // namespace performance
|
||||
} // namespace tidy
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NOEXCEPTMOVECONSTRUCTORCHECK_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H
|
@ -16,7 +16,9 @@
|
||||
#include "InefficientAlgorithmCheck.h"
|
||||
#include "InefficientStringConcatenationCheck.h"
|
||||
#include "InefficientVectorOperationCheck.h"
|
||||
#include "MoveConstArgCheck.h"
|
||||
#include "MoveConstructorInitCheck.h"
|
||||
#include "NoexceptMoveConstructorCheck.h"
|
||||
#include "TypePromotionInMathFnCheck.h"
|
||||
#include "UnnecessaryCopyInitialization.h"
|
||||
#include "UnnecessaryValueParamCheck.h"
|
||||
@ -40,8 +42,12 @@ public:
|
||||
"performance-inefficient-string-concatenation");
|
||||
CheckFactories.registerCheck<InefficientVectorOperationCheck>(
|
||||
"performance-inefficient-vector-operation");
|
||||
CheckFactories.registerCheck<MoveConstArgCheck>(
|
||||
"performance-move-const-arg");
|
||||
CheckFactories.registerCheck<MoveConstructorInitCheck>(
|
||||
"performance-move-constructor-init");
|
||||
CheckFactories.registerCheck<NoexceptMoveConstructorCheck>(
|
||||
"performance-noexcept-move-constructor");
|
||||
CheckFactories.registerCheck<TypePromotionInMathFnCheck>(
|
||||
"performance-type-promotion-in-math-fn");
|
||||
CheckFactories.registerCheck<UnnecessaryCopyInitialization>(
|
||||
|
@ -62,6 +62,12 @@ Improvements to clang-tidy
|
||||
|
||||
Add new check to detect the use of OSSpinlock.
|
||||
|
||||
- The 'misc-move-const-arg' check was renamed to `performance-move-const-arg
|
||||
<http://clang.llvm.org/extra/clang-tidy/checks/performance-move-const-arg.html>`_
|
||||
|
||||
- The 'misc-noexcept-move-constructor' check was renamed to `performance-noexcept-move-constructor
|
||||
<http://clang.llvm.org/extra/clang-tidy/checks/performance-noexcept-move-constructor.html>`_
|
||||
|
||||
- The 'misc-move-constructor-init' check was renamed to `performance-move-constructor-init
|
||||
<http://clang.llvm.org/extra/clang-tidy/checks/performance-move-constructor-init.html>`_
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
.. title:: clang-tidy - hicpp-move-const-arg
|
||||
.. meta::
|
||||
:http-equiv=refresh: 5;URL=misc-move-const-arg.html
|
||||
:http-equiv=refresh: 5;URL=performance-move-const-arg.html
|
||||
|
||||
hicpp-move-const-arg
|
||||
====================
|
||||
|
||||
The `hicpp-move-const-arg` check is an alias, please see
|
||||
`misc-move-const-arg <misc-move-const-arg.html>`_ for more information.
|
||||
`performance-move-const-arg <performance-move-const-arg.html>`_ for more information.
|
||||
It enforces the `rule 17.3.1 <http://www.codingstandard.com/rule/17-3-1-do-not-use-stdmove-on-objects-declared-with-const-or-const-type/>`_.
|
||||
|
@ -93,7 +93,7 @@ Clang-Tidy Checks
|
||||
hicpp-function-size (redirects to readability-function-size) <hicpp-function-size>
|
||||
hicpp-invalid-access-moved (redirects to bugprone-use-after-move) <hicpp-invalid-access-moved>
|
||||
hicpp-member-init (redirects to cppcoreguidelines-pro-type-member-init) <hicpp-member-init>
|
||||
hicpp-move-const-arg (redirects to misc-move-const-arg) <hicpp-move-const-arg>
|
||||
hicpp-move-const-arg (redirects to performance-move-const-arg) <hicpp-move-const-arg>
|
||||
hicpp-named-parameter (redirects to readability-named-parameter) <hicpp-named-parameter>
|
||||
hicpp-new-delete-operators (redirects to misc-new-delete-overloads) <hicpp-new-delete-operators>
|
||||
hicpp-no-array-decay (redirects to cppcoreguidelines-pro-bounds-array-to-pointer-decay) <hicpp-no-array-decay>
|
||||
@ -124,9 +124,7 @@ Clang-Tidy Checks
|
||||
misc-macro-repeated-side-effects
|
||||
misc-misplaced-const
|
||||
misc-misplaced-widening-cast
|
||||
misc-move-const-arg
|
||||
misc-new-delete-overloads
|
||||
misc-noexcept-move-constructor
|
||||
misc-non-copyable-objects
|
||||
misc-redundant-expression
|
||||
misc-sizeof-container
|
||||
@ -183,7 +181,9 @@ Clang-Tidy Checks
|
||||
performance-inefficient-algorithm
|
||||
performance-inefficient-string-concatenation
|
||||
performance-inefficient-vector-operation
|
||||
performance-move-const-arg
|
||||
performance-move-constructor-init
|
||||
performance-noexcept-move-constructor
|
||||
performance-type-promotion-in-math-fn
|
||||
performance-unnecessary-copy-initialization
|
||||
performance-unnecessary-value-param
|
||||
|
@ -1,7 +1,7 @@
|
||||
.. title:: clang-tidy - misc-move-const-arg
|
||||
.. title:: clang-tidy - performance-move-const-arg
|
||||
|
||||
misc-move-const-arg
|
||||
===================
|
||||
performance-move-const-arg
|
||||
==========================
|
||||
|
||||
The check warns
|
||||
|
@ -1,7 +1,7 @@
|
||||
.. title:: clang-tidy - misc-noexcept-move-constructor
|
||||
.. title:: clang-tidy - performance-noexcept-move-constructor
|
||||
|
||||
misc-noexcept-move-constructor
|
||||
==============================
|
||||
performance-noexcept-move-constructor
|
||||
=====================================
|
||||
|
||||
|
||||
The check flags user-defined move constructors and assignment operators not
|
@ -202,7 +202,7 @@ struct S {
|
||||
template <typename T, int N> struct array { T A[N]; };
|
||||
|
||||
// Test that types that are trivially copyable will not use std::move. This will
|
||||
// cause problems with misc-move-const-arg, as it will revert it.
|
||||
// cause problems with performance-move-const-arg, as it will revert it.
|
||||
struct T {
|
||||
T(array<int, 10> a) : a_(a) {}
|
||||
// CHECK-FIXES: T(array<int, 10> a) : a_(a) {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// RUN: %check_clang_tidy %s misc-move-const-arg %t \
|
||||
// RUN: %check_clang_tidy %s performance-move-const-arg %t \
|
||||
// RUN: -config='{CheckOptions: \
|
||||
// RUN: [{key: misc-move-const-arg.CheckTriviallyCopyableMove, value: 0}]}' \
|
||||
// RUN: [{key: performance-move-const-arg.CheckTriviallyCopyableMove, value: 0}]}' \
|
||||
// RUN: -- -std=c++14
|
||||
|
||||
namespace std {
|
||||
@ -39,7 +39,7 @@ void moveToConstReferencePositives() {
|
||||
|
||||
// Basic case. It is here just to have a single "detected and fixed" case.
|
||||
callByConstRef(std::move(obj));
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [misc-move-const-arg]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
|
||||
// CHECK-FIXES: callByConstRef(obj);
|
||||
}
|
||||
|
@ -1,13 +1,23 @@
|
||||
// RUN: %check_clang_tidy %s misc-move-const-arg %t
|
||||
// RUN: %check_clang_tidy %s performance-move-const-arg %t
|
||||
|
||||
namespace std {
|
||||
template <typename> struct remove_reference;
|
||||
template <typename>
|
||||
struct remove_reference;
|
||||
|
||||
template <typename _Tp> struct remove_reference { typedef _Tp type; };
|
||||
template <typename _Tp>
|
||||
struct remove_reference {
|
||||
typedef _Tp type;
|
||||
};
|
||||
|
||||
template <typename _Tp> struct remove_reference<_Tp &> { typedef _Tp type; };
|
||||
template <typename _Tp>
|
||||
struct remove_reference<_Tp &> {
|
||||
typedef _Tp type;
|
||||
};
|
||||
|
||||
template <typename _Tp> struct remove_reference<_Tp &&> { typedef _Tp type; };
|
||||
template <typename _Tp>
|
||||
struct remove_reference<_Tp &&> {
|
||||
typedef _Tp type;
|
||||
};
|
||||
|
||||
template <typename _Tp>
|
||||
constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {
|
||||
@ -38,13 +48,13 @@ void f(TriviallyCopyable) {}
|
||||
void g() {
|
||||
TriviallyCopyable obj;
|
||||
f(std::move(obj));
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [misc-move-const-arg]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
|
||||
// CHECK-FIXES: f(obj);
|
||||
}
|
||||
|
||||
int f1() {
|
||||
return std::move(42);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'int' has no effect; remove std::move() [misc-move-const-arg]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the expression of the trivially-copyable type 'int' has no effect; remove std::move() [performance-move-const-arg]
|
||||
// CHECK-FIXES: return 42;
|
||||
}
|
||||
|
||||
@ -64,11 +74,14 @@ A f4(A x4) { return std::move(x4); }
|
||||
|
||||
A f5(const A x5) {
|
||||
return std::move(x5);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [misc-move-const-arg]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
|
||||
// CHECK-FIXES: return x5;
|
||||
}
|
||||
|
||||
template <typename T> T f6(const T x6) { return std::move(x6); }
|
||||
template <typename T>
|
||||
T f6(const T x6) {
|
||||
return std::move(x6);
|
||||
}
|
||||
|
||||
void f7() { int a = f6(10); }
|
||||
|
||||
@ -83,9 +96,10 @@ void f8() {
|
||||
#define M2(x) std::move(x)
|
||||
int f9() { return M2(1); }
|
||||
|
||||
template <typename T> T f10(const int x10) {
|
||||
template <typename T>
|
||||
T f10(const int x10) {
|
||||
return std::move(x10);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [misc-move-const-arg]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [performance-move-const-arg]
|
||||
// CHECK-FIXES: return x10;
|
||||
}
|
||||
void f11() {
|
||||
@ -94,7 +108,7 @@ void f11() {
|
||||
}
|
||||
|
||||
class NoMoveSemantics {
|
||||
public:
|
||||
public:
|
||||
NoMoveSemantics();
|
||||
NoMoveSemantics(const NoMoveSemantics &);
|
||||
|
||||
@ -134,7 +148,7 @@ void moveToConstReferencePositives() {
|
||||
}
|
||||
|
||||
class MoveSemantics {
|
||||
public:
|
||||
public:
|
||||
MoveSemantics();
|
||||
MoveSemantics(MoveSemantics &&);
|
||||
|
@ -1,8 +1,8 @@
|
||||
// RUN: %check_clang_tidy %s misc-noexcept-move-constructor %t
|
||||
// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t
|
||||
|
||||
class A {
|
||||
A(A &&);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [misc-noexcept-move-constructor]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [performance-noexcept-move-constructor]
|
||||
A &operator=(A &&);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
|
||||
};
|
||||
@ -10,7 +10,7 @@ class A {
|
||||
struct B {
|
||||
static constexpr bool kFalse = false;
|
||||
B(B &&) noexcept(kFalse);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [misc-noexcept-move-constructor]
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
|
||||
};
|
||||
|
||||
class OK {};
|
||||
@ -21,10 +21,10 @@ void f() {
|
||||
}
|
||||
|
||||
class OK1 {
|
||||
public:
|
||||
public:
|
||||
OK1();
|
||||
OK1(const OK1 &);
|
||||
OK1(OK1&&) noexcept;
|
||||
OK1(OK1 &&) noexcept;
|
||||
OK1 &operator=(OK1 &&) noexcept;
|
||||
void f();
|
||||
void g() noexcept;
|
Loading…
Reference in New Issue
Block a user