This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Allow explicit throwing in bugprone-exception-escape for special functions
ClosedPublic

Authored by PiotrZSL on Jun 21 2023, 7:16 AM.

Details

Summary

Functions declared explicitly with noexcept(false) or throw(exception)
will be excluded from the analysis, as even though it is not recommended for
functions like swap, main, move constructors and assignment operators,
and destructors, it is a clear indication of the developer's intention and
should be respected.

Fixes: #40583, #55143

Diff Detail

Event Timeline

PiotrZSL created this revision.Jun 21 2023, 7:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 7:17 AM
Herald added a subscriber: xazax.hun. · View Herald Transcript
PiotrZSL requested review of this revision.Jun 21 2023, 7:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 7:17 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Eugene.Zelenko added inline comments.
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
29

Double period.

PiotrZSL edited the summary of this revision. (Show Details)Jun 21 2023, 10:58 AM

Apart from some nits I think this patch looks good.

clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
26

How about creating an isExplicitThrow() helper function inside ExceptionSpecificationType.h, where these enums are defined? That way if one more enum is added, it will be more convenient to update the explicit throw checks, not to mention it can also be reused in other checkers if needed.

clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
14

Why remove noexcept(true)?

25–29
PiotrZSL marked 4 inline comments as done.Jun 23 2023, 1:17 PM
PiotrZSL added inline comments.
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
14

You right, this not need to be changed.

PiotrZSL updated this revision to Diff 534059.Jun 23 2023, 1:18 PM
PiotrZSL marked an inline comment as done.

Review fixes

Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2023, 1:18 PM
carlosgalvezp accepted this revision.Jul 18 2023, 1:04 PM

LGTM, thanks for the fix!

This revision is now accepted and ready to land.Jul 18 2023, 1:04 PM