Skip to content

Commit 4b433cb

Browse files
vbvictorlocalspook
andauthored
[clang-tidy] Rename 'cert-err60-cpp' to 'bugprone-exception-copy-constructor-throws' (#164061)
Closes #157299. --------- Co-authored-by: Victor Chernyakin <chernyakin.victor.j@outlook.com>
1 parent 6408703 commit 4b433cb

File tree

11 files changed

+68
-21
lines changed

11 files changed

+68
-21
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "DynamicStaticInitializersCheck.h"
3131
#include "EasilySwappableParametersCheck.h"
3232
#include "EmptyCatchCheck.h"
33+
#include "ExceptionCopyConstructorThrowsCheck.h"
3334
#include "ExceptionEscapeCheck.h"
3435
#include "FloatLoopCounterCheck.h"
3536
#include "FoldInitTypeCheck.h"
@@ -155,6 +156,8 @@ class BugproneModule : public ClangTidyModule {
155156
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
156157
"bugprone-easily-swappable-parameters");
157158
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
159+
CheckFactories.registerCheck<ExceptionCopyConstructorThrowsCheck>(
160+
"bugprone-exception-copy-constructor-throws");
158161
CheckFactories.registerCheck<ExceptionEscapeCheck>(
159162
"bugprone-exception-escape");
160163
CheckFactories.registerCheck<FloatLoopCounterCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule STATIC
2626
DynamicStaticInitializersCheck.cpp
2727
EasilySwappableParametersCheck.cpp
2828
EmptyCatchCheck.cpp
29+
ExceptionCopyConstructorThrowsCheck.cpp
2930
ExceptionEscapeCheck.cpp
3031
FloatLoopCounterCheck.cpp
3132
FoldInitTypeCheck.cpp

clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp

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

9-
#include "ThrownExceptionTypeCheck.h"
9+
#include "ExceptionCopyConstructorThrowsCheck.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

17-
void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
17+
void ExceptionCopyConstructorThrowsCheck::registerMatchers(
18+
MatchFinder *Finder) {
1819
Finder->addMatcher(
1920
traverse(
2021
TK_AsIs,
@@ -25,10 +26,11 @@ void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
2526
this);
2627
}
2728

28-
void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
29+
void ExceptionCopyConstructorThrowsCheck::check(
30+
const MatchFinder::MatchResult &Result) {
2931
const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
3032
diag(E->getExprLoc(),
3133
"thrown exception type is not nothrow copy constructible");
3234
}
3335

34-
} // namespace clang::tidy::cert
36+
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h renamed to clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h

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

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
1111

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

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

1616
/// Checks whether a thrown object is nothrow copy constructible.
1717
///
1818
/// For the user-facing documentation see:
19-
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/err60-cpp.html
20-
class ThrownExceptionTypeCheck : public ClangTidyCheck {
19+
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-copy-constructor-throws.html
20+
class ExceptionCopyConstructorThrowsCheck : public ClangTidyCheck {
2121
public:
22-
ThrownExceptionTypeCheck(StringRef Name, ClangTidyContext *Context)
22+
ExceptionCopyConstructorThrowsCheck(StringRef Name, ClangTidyContext *Context)
2323
: ClangTidyCheck(Name, Context) {}
2424
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2525
return LangOpts.CPlusPlus;
@@ -28,6 +28,6 @@ class ThrownExceptionTypeCheck : public ClangTidyCheck {
2828
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2929
};
3030

31-
} // namespace clang::tidy::cert
31+
} // namespace clang::tidy::bugprone
3232

33-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
33+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "../bugprone/CommandProcessorCheck.h"
1414
#include "../bugprone/CopyConstructorMutatesArgumentCheck.h"
1515
#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
16+
#include "../bugprone/ExceptionCopyConstructorThrowsCheck.h"
1617
#include "../bugprone/FloatLoopCounterCheck.h"
1718
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
1819
#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
@@ -41,7 +42,6 @@
4142
#include "../readability/UppercaseLiteralSuffixCheck.h"
4243
#include "LimitedRandomnessCheck.h"
4344
#include "ProperlySeededRandomGeneratorCheck.h"
44-
#include "ThrownExceptionTypeCheck.h"
4545

4646
namespace {
4747

@@ -262,7 +262,8 @@ class CERTModule : public ClangTidyModule {
262262
"cert-err52-cpp");
263263
CheckFactories.registerCheck<bugprone::ThrowingStaticInitializationCheck>(
264264
"cert-err58-cpp");
265-
CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
265+
CheckFactories.registerCheck<bugprone::ExceptionCopyConstructorThrowsCheck>(
266+
"cert-err60-cpp");
266267
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
267268
"cert-err61-cpp");
268269
// MEM

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_clang_library(clangTidyCERTModule STATIC
77
CERTTidyModule.cpp
88
LimitedRandomnessCheck.cpp
99
ProperlySeededRandomGeneratorCheck.cpp
10-
ThrownExceptionTypeCheck.cpp
1110

1211
LINK_LIBS
1312
clangTidy

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ New check aliases
269269
<clang-tidy/checks/bugprone/throwing-static-initialization>`
270270
keeping initial check as an alias to the new one.
271271

272+
- Renamed :doc:`cert-err60-cpp <clang-tidy/checks/cert/err60-cpp>` to
273+
:doc:`bugprone-exception-copy-constructor-throws
274+
<clang-tidy/checks/bugprone/exception-copy-constructor-throws>`
275+
272276
- Renamed :doc:`cert-flp30-c <clang-tidy/checks/cert/flp30-c>` to
273277
:doc:`bugprone-float-loop-counter
274278
<clang-tidy/checks/bugprone/float-loop-counter>`
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. title:: clang-tidy - bugprone-exception-copy-constructor-throws
2+
3+
bugprone-exception-copy-constructor-throws
4+
==========================================
5+
6+
Checks whether a thrown object's copy constructor can throw.
7+
8+
Exception objects are required to be copy constructible in C++. However, an
9+
exception's copy constructor should not throw to avoid potential issues when
10+
unwinding the stack. If an exception is thrown during stack unwinding (such
11+
as from a copy constructor of an exception object), the program will
12+
terminate via ``std::terminate``.
13+
14+
.. code-block:: c++
15+
16+
class SomeException {
17+
public:
18+
SomeException() = default;
19+
SomeException(const SomeException&) { /* may throw */ }
20+
};
21+
22+
void f() {
23+
throw SomeException(); // warning: thrown exception type's copy constructor can throw
24+
}
25+
26+
References
27+
----------
28+
29+
This check corresponds to the CERT C++ Coding Standard rule
30+
`ERR60-CPP. Exception objects must be nothrow copy constructible
31+
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.. title:: clang-tidy - cert-err60-cpp
2+
.. meta::
3+
:http-equiv=refresh: 5;URL=../bugprone/exception-copy-constructor-throws.html
24

35
cert-err60-cpp
46
==============
57

6-
This check flags all throw expressions where the exception object is not nothrow
7-
copy constructible.
8+
The `cert-err60-cpp` check is an alias, please see
9+
`bugprone-exception-copy-constructor-throws <../bugprone/exception-copy-constructor-throws.html>`_
10+
for more information.
811

912
This check corresponds to the CERT C++ Coding Standard rule
1013
`ERR60-CPP. Exception objects must be nothrow copy constructible
11-
<https://www.securecoding.cert.org/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.
14+
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Clang-Tidy Checks
9898
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
9999
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
100100
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
101+
:doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
101102
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
102103
:doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
103104
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
@@ -180,6 +181,7 @@ Clang-Tidy Checks
180181
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
181182
:doc:`cert-err33-c <cert/err33-c>`,
182183
:doc:`cert-err60-cpp <cert/err60-cpp>`,
184+
:doc:`cert-flp30-c <cert/flp30-c>`,
183185
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
184186
:doc:`cert-msc51-cpp <cert/msc51-cpp>`,
185187
:doc:`cert-oop58-cpp <cert/oop58-cpp>`,
@@ -449,6 +451,7 @@ Check aliases
449451
:doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
450452
:doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
451453
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
454+
:doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
452455
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
453456
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
454457
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,

0 commit comments

Comments
 (0)