mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-10 03:13:34 +00:00
[clang-tidy] Treat all types with non-trivial destructors as RAII.
This solves some false negatives at a cost of adding some false positives that can be fixed easily and (almost) automatically. llvm-svn: 237120
This commit is contained in:
parent
c07f848785
commit
bdaa681fc6
@ -15,9 +15,9 @@ using namespace clang::ast_matchers;
|
||||
|
||||
namespace clang {
|
||||
namespace ast_matchers {
|
||||
AST_MATCHER(CXXRecordDecl, hasUserDeclaredDestructor) {
|
||||
AST_MATCHER(CXXRecordDecl, hasNonTrivialDestructor) {
|
||||
// TODO: If the dtor is there but empty we don't want to warn either.
|
||||
return Node.hasDefinition() && Node.hasUserDeclaredDestructor();
|
||||
return Node.hasDefinition() && Node.hasNonTrivialDestructor();
|
||||
}
|
||||
} // namespace ast_matchers
|
||||
|
||||
@ -32,7 +32,7 @@ void UnusedRAIICheck::registerMatchers(MatchFinder *Finder) {
|
||||
Finder->addMatcher(
|
||||
exprWithCleanups(unless(isInTemplateInstantiation()),
|
||||
hasParent(compoundStmt().bind("compound")),
|
||||
hasType(recordDecl(hasUserDeclaredDestructor())),
|
||||
hasType(recordDecl(hasNonTrivialDestructor())),
|
||||
anyOf(has(BindTemp), has(functionalCastExpr(
|
||||
has(BindTemp))))).bind("expr"),
|
||||
this);
|
||||
|
@ -10,6 +10,10 @@ struct Foo {
|
||||
|
||||
struct Bar {
|
||||
Bar();
|
||||
};
|
||||
|
||||
struct FooBar {
|
||||
FooBar();
|
||||
Foo f;
|
||||
};
|
||||
|
||||
@ -47,6 +51,10 @@ void test() {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
|
||||
// CHECK-FIXES: TFoo<int> give_me_a_name(23);
|
||||
|
||||
FooBar();
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: object destroyed immediately after creation; did you mean to name the object?
|
||||
// CHECK-FIXES: FooBar give_me_a_name;
|
||||
|
||||
Bar();
|
||||
f();
|
||||
qux<Foo>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user