Skip to content

Commit ed25853

Browse files
committed
Rename to bugprone-exception-copy-constructor-throws
1 parent dac6845 commit ed25853

File tree

11 files changed

+63
-66
lines changed

11 files changed

+63
-66
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include "DynamicStaticInitializersCheck.h"
2929
#include "EasilySwappableParametersCheck.h"
3030
#include "EmptyCatchCheck.h"
31+
#include "ExceptionCopyConstructorThrowsCheck.h"
3132
#include "ExceptionEscapeCheck.h"
32-
#include "ExceptionTypeNotNothrowCopyConstructibleCheck.h"
3333
#include "FoldInitTypeCheck.h"
3434
#include "ForwardDeclarationNamespaceCheck.h"
3535
#include "ForwardingReferenceOverloadCheck.h"
@@ -147,10 +147,10 @@ class BugproneModule : public ClangTidyModule {
147147
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
148148
"bugprone-easily-swappable-parameters");
149149
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
150+
CheckFactories.registerCheck<ExceptionCopyConstructorThrowsCheck>(
151+
"bugprone-exception-copy-constructor-throws");
150152
CheckFactories.registerCheck<ExceptionEscapeCheck>(
151153
"bugprone-exception-escape");
152-
CheckFactories.registerCheck<ExceptionTypeNotNothrowCopyConstructibleCheck>(
153-
"bugprone-exception-type-not-nothrow-copy-constructible");
154154
CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
155155
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
156156
"bugprone-forward-declaration-namespace");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ add_clang_library(clangTidyBugproneModule STATIC
2424
DynamicStaticInitializersCheck.cpp
2525
EasilySwappableParametersCheck.cpp
2626
EmptyCatchCheck.cpp
27+
ExceptionCopyConstructorThrowsCheck.cpp
2728
ExceptionEscapeCheck.cpp
28-
ExceptionTypeNotNothrowCopyConstructibleCheck.cpp
2929
FoldInitTypeCheck.cpp
3030
ForwardDeclarationNamespaceCheck.cpp
3131
ForwardingReferenceOverloadCheck.cpp
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "ExceptionTypeNotNothrowCopyConstructibleCheck.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

1515
namespace clang::tidy::bugprone {
1616

17-
void ExceptionTypeNotNothrowCopyConstructibleCheck::registerMatchers(
17+
void ExceptionCopyConstructorThrowsCheck::registerMatchers(
1818
MatchFinder *Finder) {
1919
Finder->addMatcher(
2020
traverse(
@@ -26,11 +26,10 @@ void ExceptionTypeNotNothrowCopyConstructibleCheck::registerMatchers(
2626
this);
2727
}
2828

29-
void ExceptionTypeNotNothrowCopyConstructibleCheck::check(
29+
void ExceptionCopyConstructorThrowsCheck::check(
3030
const MatchFinder::MatchResult &Result) {
3131
const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
32-
diag(E->getExprLoc(),
33-
"thrown exception type is not nothrow copy constructible");
32+
diag(E->getExprLoc(), "thrown exception type's copy constructor can throw");
3433
}
3534

3635
} // namespace clang::tidy::bugprone
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONTYPENOTNOTHROWCOPYCONSTRUCTIBLECHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONTYPENOTNOTHROWCOPYCONSTRUCTIBLECHECK_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

@@ -16,11 +16,10 @@ namespace clang::tidy::bugprone {
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/bugprone/exception-type-not-nothrow-copy-constructible.html
20-
class ExceptionTypeNotNothrowCopyConstructibleCheck : 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-
ExceptionTypeNotNothrowCopyConstructibleCheck(StringRef Name,
23-
ClangTidyContext *Context)
22+
ExceptionCopyConstructorThrowsCheck(StringRef Name, ClangTidyContext *Context)
2423
: ClangTidyCheck(Name, Context) {}
2524
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2625
return LangOpts.CPlusPlus;
@@ -31,4 +30,4 @@ class ExceptionTypeNotNothrowCopyConstructibleCheck : public ClangTidyCheck {
3130

3231
} // namespace clang::tidy::bugprone
3332

34-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONTYPENOTNOTHROWCOPYCONSTRUCTIBLECHECK_H
33+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../bugprone/BadSignalToKillThreadCheck.h"
1313
#include "../bugprone/CommandProcessorCheck.h"
14-
#include "../bugprone/ExceptionTypeNotNothrowCopyConstructibleCheck.h"
14+
#include "../bugprone/ExceptionCopyConstructorThrowsCheck.h"
1515
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
1616
#include "../bugprone/ReservedIdentifierCheck.h"
1717
#include "../bugprone/SignalHandlerCheck.h"
@@ -261,9 +261,8 @@ class CERTModule : public ClangTidyModule {
261261
"cert-err52-cpp");
262262
CheckFactories.registerCheck<bugprone::ThrowingStaticInitializationCheck>(
263263
"cert-err58-cpp");
264-
CheckFactories
265-
.registerCheck<bugprone::ExceptionTypeNotNothrowCopyConstructibleCheck>(
266-
"cert-err60-cpp");
264+
CheckFactories.registerCheck<bugprone::ExceptionCopyConstructorThrowsCheck>(
265+
"cert-err60-cpp");
267266
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
268267
"cert-err61-cpp");
269268
// MEM

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ New check aliases
250250
keeping initial check as an alias to the new one.
251251

252252
- Renamed :doc:`cert-err60-cpp <clang-tidy/checks/cert/err60-cpp>` to
253-
:doc:`bugprone-exception-type-not-nothrow-copy-constructible
254-
<clang-tidy/checks/bugprone/exception-type-not-nothrow-copy-constructible>`
253+
:doc:`bugprone-exception-copy-constructor-throws
254+
<clang-tidy/checks/bugprone/exception-copy-constructor-throws>`
255255
keeping initial check as an alias to the new one.
256256

257257
Changes in existing checks
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>`_.

clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-type-not-nothrow-copy-constructible.rst

Lines changed: 0 additions & 31 deletions
This file was deleted.

clang-tools-extra/docs/clang-tidy/checks/cert/err60-cpp.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.. title:: clang-tidy - cert-err60-cpp
22
.. meta::
3-
:http-equiv=refresh: 5;URL=../bugprone/exception-type-not-nothrow-copy-constructible.html
3+
:http-equiv=refresh: 5;URL=../bugprone/exception-copy-constructor-throws.html
44

55
cert-err60-cpp
66
==============
77

88
The `cert-err60-cpp` check is an alias, please see
9-
`bugprone-exception-type-not-nothrow-copy-constructible <../bugprone/exception-type-not-nothrow-copy-constructible.html>`_
9+
`bugprone-exception-copy-constructor-throws <../bugprone/exception-copy-constructor-throws.html>`_
1010
for more information.
1111

1212
This check corresponds to the CERT C++ Coding Standard rule

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ Clang-Tidy Checks
9696
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
9797
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
9898
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
99+
:doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
99100
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
100-
:doc:`bugprone-exception-type-not-nothrow-copy-constructible <bugprone/exception-type-not-nothrow-copy-constructible>`,
101101
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
102102
:doc:`bugprone-forward-declaration-namespace <bugprone/forward-declaration-namespace>`,
103103
:doc:`bugprone-forwarding-reference-overload <bugprone/forwarding-reference-overload>`,
@@ -446,7 +446,7 @@ Check aliases
446446
:doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
447447
:doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
448448
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
449-
:doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-type-not-nothrow-copy-constructible <bugprone/exception-type-not-nothrow-copy-constructible>`,
449+
:doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
450450
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
451451
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
452452
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,

0 commit comments

Comments
 (0)