Skip to content

Commit 00eacc2

Browse files
dvbukavbvictor
andauthored
[clang-tidy] Rename and move 'cert-oop58-cpp' to 'bugprone-copy-constructor-mutates-argument' (#164566)
closes #157293 --------- Co-authored-by: Baranov Victor <[email protected]>
1 parent 17ad848 commit 00eacc2

File tree

11 files changed

+47
-24
lines changed

11 files changed

+47
-24
lines changed

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "CommandProcessorCheck.h"
2323
#include "ComparePointerToMemberVirtualFunctionCheck.h"
2424
#include "CopyConstructorInitCheck.h"
25+
#include "CopyConstructorMutatesArgumentCheck.h"
2526
#include "CrtpConstructorAccessibilityCheck.h"
2627
#include "DanglingHandleCheck.h"
2728
#include "DefaultOperatorNewOnOveralignedTypeCheck.h"
@@ -141,6 +142,8 @@ class BugproneModule : public ClangTidyModule {
141142
"bugprone-compare-pointer-to-member-virtual-function");
142143
CheckFactories.registerCheck<CopyConstructorInitCheck>(
143144
"bugprone-copy-constructor-init");
145+
CheckFactories.registerCheck<CopyConstructorMutatesArgumentCheck>(
146+
"bugprone-copy-constructor-mutates-argument");
144147
CheckFactories.registerCheck<DanglingHandleCheck>(
145148
"bugprone-dangling-handle");
146149
CheckFactories.registerCheck<DefaultOperatorNewOnOveralignedTypeCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_clang_library(clangTidyBugproneModule STATIC
1818
CommandProcessorCheck.cpp
1919
ComparePointerToMemberVirtualFunctionCheck.cpp
2020
CopyConstructorInitCheck.cpp
21+
CopyConstructorMutatesArgumentCheck.cpp
2122
CrtpConstructorAccessibilityCheck.cpp
2223
DanglingHandleCheck.cpp
2324
DefaultOperatorNewOnOveralignedTypeCheck.cpp

clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "MutatingCopyCheck.h"
9+
#include "CopyConstructorMutatesArgumentCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212

1313
using namespace clang::ast_matchers;
1414

15-
namespace clang::tidy::cert {
15+
namespace clang::tidy::bugprone {
1616

1717
static constexpr llvm::StringLiteral SourceDeclName = "ChangedPVD";
1818
static constexpr llvm::StringLiteral MutatingOperatorName = "MutatingOp";
1919
static constexpr llvm::StringLiteral MutatingCallName = "MutatingCall";
2020

21-
void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
21+
void CopyConstructorMutatesArgumentCheck::registerMatchers(
22+
MatchFinder *Finder) {
2223
const auto MemberExprOrSourceObject = anyOf(
2324
memberExpr(),
2425
declRefExpr(to(decl(equalsBoundNode(std::string(SourceDeclName))))));
@@ -60,7 +61,8 @@ void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
6061
this);
6162
}
6263

63-
void MutatingCopyCheck::check(const MatchFinder::MatchResult &Result) {
64+
void CopyConstructorMutatesArgumentCheck::check(
65+
const MatchFinder::MatchResult &Result) {
6466
if (const auto *MemberCall =
6567
Result.Nodes.getNodeAs<CXXMemberCallExpr>(MutatingCallName))
6668
diag(MemberCall->getBeginLoc(), "call mutates copied object");
@@ -69,4 +71,4 @@ void MutatingCopyCheck::check(const MatchFinder::MatchResult &Result) {
6971
diag(Assignment->getBeginLoc(), "mutating copied object");
7072
}
7173

72-
} // namespace clang::tidy::cert
74+
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h renamed to clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

14-
namespace clang::tidy::cert {
14+
namespace clang::tidy::bugprone {
1515

1616
/// Finds assignments to the copied object and its direct or indirect members
1717
/// in copy constructors and copy assignment operators.
1818
///
1919
/// For the user-facing documentation see:
20-
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/oop58-cpp.html
21-
class MutatingCopyCheck : public ClangTidyCheck {
20+
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.html
21+
class CopyConstructorMutatesArgumentCheck : public ClangTidyCheck {
2222
public:
23-
MutatingCopyCheck(StringRef Name, ClangTidyContext *Context)
23+
CopyConstructorMutatesArgumentCheck(StringRef Name, ClangTidyContext *Context)
2424
: ClangTidyCheck(Name, Context) {}
2525
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2626
return LangOpts.CPlusPlus;
@@ -29,6 +29,6 @@ class MutatingCopyCheck : public ClangTidyCheck {
2929
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3030
};
3131

32-
} // namespace clang::tidy::cert
32+
} // namespace clang::tidy::bugprone
3333

34-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
34+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../bugprone/BadSignalToKillThreadCheck.h"
1313
#include "../bugprone/CommandProcessorCheck.h"
14+
#include "../bugprone/CopyConstructorMutatesArgumentCheck.h"
1415
#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
1516
#include "../bugprone/FloatLoopCounterCheck.h"
1617
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
@@ -39,7 +40,6 @@
3940
#include "../readability/EnumInitialValueCheck.h"
4041
#include "../readability/UppercaseLiteralSuffixCheck.h"
4142
#include "LimitedRandomnessCheck.h"
42-
#include "MutatingCopyCheck.h"
4343
#include "ProperlySeededRandomGeneratorCheck.h"
4444
#include "ThrownExceptionTypeCheck.h"
4545

@@ -282,7 +282,8 @@ class CERTModule : public ClangTidyModule {
282282
"cert-oop54-cpp");
283283
CheckFactories.registerCheck<bugprone::RawMemoryCallOnNonTrivialTypeCheck>(
284284
"cert-oop57-cpp");
285-
CheckFactories.registerCheck<MutatingCopyCheck>("cert-oop58-cpp");
285+
CheckFactories.registerCheck<bugprone::CopyConstructorMutatesArgumentCheck>(
286+
"cert-oop58-cpp");
286287

287288
// C checkers
288289
// ARR

clang-tools-extra/clang-tidy/cert/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS
66
add_clang_library(clangTidyCERTModule STATIC
77
CERTTidyModule.cpp
88
LimitedRandomnessCheck.cpp
9-
MutatingCopyCheck.cpp
109
ProperlySeededRandomGeneratorCheck.cpp
1110
ThrownExceptionTypeCheck.cpp
1211

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ New check aliases
284284
<clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type>`
285285
keeping initial check as an alias to the new one.
286286

287+
- Renamed :doc:`cert-oop58-cpp <clang-tidy/checks/cert/oop58-cpp>` to
288+
:doc:`bugprone-copy-constructor-mutates-argument
289+
<clang-tidy/checks/bugprone/copy-constructor-mutates-argument>`
290+
keeping initial check as an alias to the new one.
291+
287292
Changes in existing checks
288293
^^^^^^^^^^^^^^^^^^^^^^^^^^
289294

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. title:: clang-tidy - bugprone-copy-constructor-mutates-argument
2+
3+
bugprone-copy-constructor-mutates-argument
4+
==========================================
5+
6+
Finds assignments to the copied object and its direct or indirect members
7+
in copy constructors and copy assignment operators.
8+
9+
This check corresponds to the CERT C Coding Standard rule
10+
`OOP58-CPP. Copy operations must not mutate the source object
11+
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object>`_.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
.. title:: clang-tidy - cert-mutating-copy
1+
.. title:: clang-tidy - cert-oop58-cpp
2+
.. meta::
3+
:http-equiv=refresh: 5;URL=../bugprone/copy-constructor-mutates-argument.html
24

35
cert-oop58-cpp
46
==============
57

6-
Finds assignments to the copied object and its direct or indirect members
7-
in copy constructors and copy assignment operators.
8-
9-
This check corresponds to the CERT C Coding Standard rule
10-
`OOP58-CPP. Copy operations must not mutate the source object
11-
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP58-CPP.+Copy+operations+must+not+mutate+the+source+object>`_.
8+
The `cert-oop58-cpp` check is an alias, please see
9+
:doc:`bugprone-copy-constructor-mutates-argument <../bugprone/copy-constructor-mutates-argument>`
10+
for more information.

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Clang-Tidy Checks
9090
:doc:`bugprone-command-processor <bugprone/command-processor>`,
9191
:doc:`bugprone-compare-pointer-to-member-virtual-function <bugprone/compare-pointer-to-member-virtual-function>`,
9292
:doc:`bugprone-copy-constructor-init <bugprone/copy-constructor-init>`, "Yes"
93+
:doc:`bugprone-copy-constructor-mutates-argument <bugprone/copy-constructor-mutates-argument>`,
9394
:doc:`bugprone-crtp-constructor-accessibility <bugprone/crtp-constructor-accessibility>`, "Yes"
9495
:doc:`bugprone-dangling-handle <bugprone/dangling-handle>`,
9596
:doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
@@ -463,6 +464,7 @@ Check aliases
463464
:doc:`cert-oop11-cpp <cert/oop11-cpp>`, :doc:`performance-move-constructor-init <performance/move-constructor-init>`,
464465
:doc:`cert-oop54-cpp <cert/oop54-cpp>`, :doc:`bugprone-unhandled-self-assignment <bugprone/unhandled-self-assignment>`,
465466
:doc:`cert-oop57-cpp <cert/oop57-cpp>`, :doc:`bugprone-raw-memory-call-on-non-trivial-type <bugprone/raw-memory-call-on-non-trivial-type>`,
467+
:doc:`cert-oop58-cpp <cert/oop58-cpp>`, :doc:`bugprone-copy-constructor-mutates-argument <bugprone/copy-constructor-mutates-argument>`,
466468
:doc:`cert-pos44-c <cert/pos44-c>`, :doc:`bugprone-bad-signal-to-kill-thread <bugprone/bad-signal-to-kill-thread>`,
467469
:doc:`cert-pos47-c <cert/pos47-c>`, :doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
468470
:doc:`cert-sig30-c <cert/sig30-c>`, :doc:`bugprone-signal-handler <bugprone/signal-handler>`,

0 commit comments

Comments
 (0)