Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

bugprone-exception-escape does not warn on called constructors #51402

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR52435
Status NEW
Importance P enhancement
Reported by Bowie Owens (bowie.owens@gmail.com)
Reported on 2021-11-06 13:38:52 -0700
Last modified on 2021-11-07 11:36:25 -0800
Version unspecified
Hardware PC Linux
CC adam.balogh@ericsson.com, alexfh@google.com, djasper@google.com, eugene.zelenko@gmail.com, fabian.wolff@alumni.ethz.ch, klimek@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
clang-tidy bugprone-exception-escape does not warn on called constructors. In
the following example the constructor of B does not warn even though the
constructor of A may throw. Please amend the check to warn on called
constructors.

#include <stdexcept>

struct A {
    A() noexcept(false) { throw std::runtime_error("buh"); }
};

struct B : A {
    // clang-tidy fails to warn
    B() noexcept : A() {}
};

See warnings produced by trunk clang-tidy.

https://godbolt.org/z/dnxYeEerd

This behaviour is present in clang-tidy 13
Quuxplusone commented 3 years ago

ExceptionAnalyzer::throwsException() only looks at the bodies of function declarations, so we probably need to add a loop that goes over the initializers if the function declaration is a CXXConstructorDecl. I will give this a try.