This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Include constructor initializers in `bugprone-exception-escape` check
ClosedPublic

Authored by fwolff on Nov 9 2021, 12:27 PM.

Diff Detail

Event Timeline

fwolff created this revision.Nov 9 2021, 12:27 PM
fwolff requested review of this revision.Nov 9 2021, 12:27 PM
aaron.ballman added inline comments.Dec 8 2021, 6:07 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone-exception-escape.cpp
291–293

I think this needs additional test coverage.

Dynamic exception specifications:

struct super_throws_again {
  super_throws_again() throw(int);
};

struct sub_throws_again : super_throws_again {
  sub_throws_again() noexcept : super_throws_again() {}
};

Non-base class explicit inits:

struct init_member_throws {
  super_throws s;

  init_member_throws() noexcept : s() {}
};

Non-base class implicit inits:

struct init_member_throws {
  super_throws s;

  init_member_throws() noexcept {}
};

In-class initializers (IIRC those are modeled as a ctor init):

struct init {
  explicit init(int, int) noexcept(false);
};

struct in_class_init_throws {
  init i{1, 2};
};

I *think* all of these will wind up being covered by the code changes, but we should test them to be sure.

fwolff updated this revision to Diff 400668.Jan 17 2022, 4:29 PM
fwolff marked an inline comment as done.Jan 17 2022, 4:32 PM
fwolff added inline comments.
clang-tools-extra/test/clang-tidy/checkers/bugprone-exception-escape.cpp
291–293

Thanks a lot for your suggestions! I have added these tests, as well as some special handling for CXXDefaultInitExpr, which was necessary to get the last one to pass.

aaron.ballman accepted this revision.Jan 19 2022, 10:15 AM

LGTM, thanks for the fix!

This revision is now accepted and ready to land.Jan 19 2022, 10:15 AM
This revision was automatically updated to reflect the committed changes.
fwolff marked an inline comment as done.