Skip to content

Commit cf8d159

Browse files
committed
[clang-tidy] Rename 'cert-err60-cpp' to 'bugprone-exception-type-not-nothrow-copy-constructible'
1 parent e10e2f7 commit cf8d159

File tree

11 files changed

+71
-22
lines changed

11 files changed

+71
-22
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "EasilySwappableParametersCheck.h"
3030
#include "EmptyCatchCheck.h"
3131
#include "ExceptionEscapeCheck.h"
32+
#include "ExceptionTypeNotNothrowCopyConstructibleCheck.h"
3233
#include "FoldInitTypeCheck.h"
3334
#include "ForwardDeclarationNamespaceCheck.h"
3435
#include "ForwardingReferenceOverloadCheck.h"
@@ -148,6 +149,8 @@ class BugproneModule : public ClangTidyModule {
148149
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
149150
CheckFactories.registerCheck<ExceptionEscapeCheck>(
150151
"bugprone-exception-escape");
152+
CheckFactories.registerCheck<ExceptionTypeNotNothrowCopyConstructibleCheck>(
153+
"bugprone-exception-type-not-nothrow-copy-constructible");
151154
CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
152155
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
153156
"bugprone-forward-declaration-namespace");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_clang_library(clangTidyBugproneModule STATIC
2525
EasilySwappableParametersCheck.cpp
2626
EmptyCatchCheck.cpp
2727
ExceptionEscapeCheck.cpp
28+
ExceptionTypeNotNothrowCopyConstructibleCheck.cpp
2829
FoldInitTypeCheck.cpp
2930
ForwardDeclarationNamespaceCheck.cpp
3031
ForwardingReferenceOverloadCheck.cpp

clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/ExceptionTypeNotNothrowCopyConstructibleCheck.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 "ExceptionTypeNotNothrowCopyConstructibleCheck.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 ExceptionTypeNotNothrowCopyConstructibleCheck::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 ExceptionTypeNotNothrowCopyConstructibleCheck::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
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
//===----------------------------------------------------------------------===//
2+
//===----------------------------------------------------------------------===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
56
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67
//
78
//===----------------------------------------------------------------------===//
89

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
10+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONTYPENOTNOTHROWCOPYCONSTRUCTIBLECHECK_H
11+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONTYPENOTNOTHROWCOPYCONSTRUCTIBLECHECK_H
1112

1213
#include "../ClangTidyCheck.h"
1314

14-
namespace clang::tidy::cert {
15+
namespace clang::tidy::bugprone {
1516

1617
/// Checks whether a thrown object is nothrow copy constructible.
1718
///
1819
/// For the user-facing documentation see:
19-
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/err60-cpp.html
20-
class ThrownExceptionTypeCheck : public ClangTidyCheck {
20+
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-type-not-nothrow-copy-constructible.html
21+
class ExceptionTypeNotNothrowCopyConstructibleCheck : public ClangTidyCheck {
2122
public:
22-
ThrownExceptionTypeCheck(StringRef Name, ClangTidyContext *Context)
23+
ExceptionTypeNotNothrowCopyConstructibleCheck(StringRef Name,
24+
ClangTidyContext *Context)
2325
: ClangTidyCheck(Name, Context) {}
2426
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2527
return LangOpts.CPlusPlus;
@@ -28,6 +30,6 @@ class ThrownExceptionTypeCheck : public ClangTidyCheck {
2830
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2931
};
3032

31-
} // namespace clang::tidy::cert
33+
} // namespace clang::tidy::bugprone
3234

33-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
35+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONTYPENOTNOTHROWCOPYCONSTRUCTIBLECHECK_H

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

Lines changed: 4 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/ExceptionTypeNotNothrowCopyConstructibleCheck.h"
1415
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
1516
#include "../bugprone/ReservedIdentifierCheck.h"
1617
#include "../bugprone/SignalHandlerCheck.h"
@@ -41,7 +42,6 @@
4142
#include "MutatingCopyCheck.h"
4243
#include "NonTrivialTypesLibcMemoryCallsCheck.h"
4344
#include "ProperlySeededRandomGeneratorCheck.h"
44-
#include "ThrownExceptionTypeCheck.h"
4545

4646
namespace {
4747

@@ -261,7 +261,9 @@ class CERTModule : public ClangTidyModule {
261261
"cert-err52-cpp");
262262
CheckFactories.registerCheck<bugprone::ThrowingStaticInitializationCheck>(
263263
"cert-err58-cpp");
264-
CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
264+
CheckFactories
265+
.registerCheck<bugprone::ExceptionTypeNotNothrowCopyConstructibleCheck>(
266+
"cert-err60-cpp");
265267
CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
266268
"cert-err61-cpp");
267269
// MEM

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ add_clang_library(clangTidyCERTModule STATIC
1212
MutatingCopyCheck.cpp
1313
NonTrivialTypesLibcMemoryCallsCheck.cpp
1414
ProperlySeededRandomGeneratorCheck.cpp
15-
ThrownExceptionTypeCheck.cpp
1615

1716
LINK_LIBS
1817
clangTidy

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ New check aliases
249249
<clang-tidy/checks/bugprone/throwing-static-initialization>`
250250
keeping initial check as an alias to the new one.
251251

252+
- 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>`
255+
keeping initial check as an alias to the new one.
256+
252257
Changes in existing checks
253258
^^^^^^^^^^^^^^^^^^^^^^^^^^
254259

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. title:: clang-tidy - bugprone-exception-type-not-nothrow-copy-constructible
2+
3+
bugprone-exception-type-not-nothrow-copy-constructible
4+
=======================================================
5+
6+
Checks whether a thrown object is nothrow copy constructible.
7+
8+
Exception objects are required to be copy constructible in C++. However,
9+
exceptions should generally be nothrow copy constructible to avoid potential
10+
issues when unwinding the stack. If an exception is thrown during stack
11+
unwinding (such as from a copy constructor of an exception object), the
12+
program will 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 is not nothrow copy constructible
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-type-not-nothrow-copy-constructible.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-type-not-nothrow-copy-constructible <../bugprone/exception-type-not-nothrow-copy-constructible.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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Clang-Tidy Checks
9797
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
9898
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
9999
:doc:`bugprone-exception-escape <bugprone/exception-escape>`,
100+
:doc:`bugprone-exception-type-not-nothrow-copy-constructible <bugprone/exception-type-not-nothrow-copy-constructible>`,
100101
:doc:`bugprone-fold-init-type <bugprone/fold-init-type>`,
101102
:doc:`bugprone-forward-declaration-namespace <bugprone/forward-declaration-namespace>`,
102103
:doc:`bugprone-forwarding-reference-overload <bugprone/forwarding-reference-overload>`,
@@ -175,7 +176,6 @@ Clang-Tidy Checks
175176
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
176177
:doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
177178
:doc:`cert-err33-c <cert/err33-c>`,
178-
:doc:`cert-err60-cpp <cert/err60-cpp>`,
179179
:doc:`cert-flp30-c <cert/flp30-c>`,
180180
:doc:`cert-mem57-cpp <cert/mem57-cpp>`,
181181
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
@@ -446,6 +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>`,
449450
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
450451
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
451452
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,

0 commit comments

Comments
 (0)