[PATCH] [clang-tidy] Add a check for RAII temporaries.
Daniel Jasper
djasper at google.com
Tue Jul 22 05:23:25 PDT 2014
I think, this looks good as a first version.
As discussed offline, follow-ups could:
- Ignore objects that are known to have an empty destructor.
- Ignore constructors with more than one argument (reducing false positives at the cost of false negatives).
- Distinguish the case of attempted delegated constructors (consider adding a test now).
================
Comment at: clang-tidy/misc/UnusedRAII.cpp:53
@@ +52,3 @@
+ // statement.
+ const auto *CS = Result.Nodes.getStmtAs<CompoundStmt>("compound");
+ if (E == CS->body_back())
----------------
Add a test for this code path.
================
Comment at: clang-tidy/misc/UnusedRAII.cpp:72
@@ +71,3 @@
+ if (TOE->getNumArgs() == 0)
+ D << FixItHint::CreateRemoval(
+ CharSourceRange::getTokenRange(TOE->getParenOrBraceRange()));
----------------
Hm. Fix-It-wise, wouldn't it be better to create a single replacement instead of an insertion and a removal?
================
Comment at: clang-tidy/misc/UnusedRAII.h:36
@@ +35,3 @@
+/// to be RAII objects.
+/// - Ignore objects at the end of a compound statement (doesn't change behavior)
+/// - Ignore objects returned from a call.
----------------
nit: missing period at the end of the sentence.
http://reviews.llvm.org/D4615
More information about the cfe-commits
mailing list