Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ namespace clang::tidy::bugprone {
void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxConstructExpr(
hasType(cxxRecordDecl(
isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION")))),
hasType(cxxRecordDecl(anyOf(
matchesName("[Ee]xception|EXCEPTION"),
hasAnyBase(hasType(hasCanonicalType(recordType(hasDeclaration(
cxxRecordDecl(matchesName("[Ee]xception|EXCEPTION")))))))))),
unless(anyOf(
hasAncestor(
stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ Changes in existing checks
namespace are treated as the tag or the data part of a user-defined
tagged union respectively.

- Improved :doc:`bugprone-throw-keyword-missing
<clang-tidy/checks/bugprone/throw-keyword-missing>` check by only considering
the canonical types of base classes as written.

- Improved :doc:`bugprone-unchecked-optional-access
<clang-tidy/checks/bugprone/unchecked-optional-access>` check by supporting
``NullableValue::makeValue`` and ``NullableValue::makeValueInplace`` to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ struct runtime_error : public exception {

} // namespace std

// The usage of this class should never emit a warning.
// The usage of these classes should never emit a warning.
struct RegularClass {};
struct RegularDerived : public RegularClass {};

// Class name contains the substring "exception", in certain cases using this class should emit a warning.
struct RegularException {
RegularException() {}

// Constructors with a single argument are treated differently (cxxFunctionalCastExpr).
RegularException(int) {}

typedef RegularClass RegularAlias;
};

// --------------
Expand Down Expand Up @@ -68,6 +71,10 @@ void regularClassNotThrownTest(int i) {
RegularClass();
}

void regularClassWithAliasNotThrownTest(int i) {
RegularDerived();
}

void regularClassThrownTest(int i) {
if (i < 0)
throw RegularClass();
Expand Down
Loading