[clang-tools-extra] r237120 - [clang-tidy] Treat all types with non-trivial destructors as RAII.
Alexander Kornienko
alexfh at google.com
Tue May 12 05:17:20 PDT 2015
Author: alexfh
Date: Tue May 12 07:17:20 2015
New Revision: 237120
URL: http://llvm.org/viewvc/llvm-project?rev=237120&view=rev
Log:
[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.
Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp?rev=237120&r1=237119&r2=237120&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp Tue May 12 07:17:20 2015
@@ -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(M
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);
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp?rev=237120&r1=237119&r2=237120&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-raii.cpp Tue May 12 07:17:20 2015
@@ -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>();
More information about the cfe-commits
mailing list