summaryrefslogtreecommitdiffstats
path: root/tools/clang
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 03:02:45 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-12 03:02:45 +0000
commit1ead4aab1101e2c48b2c65a83dd8c873b253871b (patch)
tree0cac0f4c9a2ff5ec97e37aa2c7c1078989c640cb /tools/clang
parent6d6a7f1e8479e3dbfeabfbfd8b152a895cbfca44 (diff)
downloadchromium_src-1ead4aab1101e2c48b2c65a83dd8c873b253871b.zip
chromium_src-1ead4aab1101e2c48b2c65a83dd8c873b253871b.tar.gz
chromium_src-1ead4aab1101e2c48b2c65a83dd8c873b253871b.tar.bz2
Teach rewrite_scoped_ptr_ctor_null about scoped_ptr_malloc's default arg
Without filtering out default args, the tool matches the implicit initializers generated for scoped_ptr_malloc<T> members... and then deletes random tokens. Needless to say, the result doesn't compile. BUG=173286 R=thakis@chromium.org Review URL: https://codereview.chromium.org/16658016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205700 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/clang')
-rw-r--r--tools/clang/rewrite_scoped_ptr_ctor_null/RewriteScopedPtrCtorNull.cpp5
-rw-r--r--tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-expected.cc6
-rw-r--r--tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-original.cc8
3 files changed, 15 insertions, 4 deletions
diff --git a/tools/clang/rewrite_scoped_ptr_ctor_null/RewriteScopedPtrCtorNull.cpp b/tools/clang/rewrite_scoped_ptr_ctor_null/RewriteScopedPtrCtorNull.cpp
index c1b25ed..26813eb 100644
--- a/tools/clang/rewrite_scoped_ptr_ctor_null/RewriteScopedPtrCtorNull.cpp
+++ b/tools/clang/rewrite_scoped_ptr_ctor_null/RewriteScopedPtrCtorNull.cpp
@@ -21,6 +21,7 @@ using clang::ast_matchers::argumentCountIs;
using clang::ast_matchers::bindTemporaryExpr;
using clang::ast_matchers::constructorDecl;
using clang::ast_matchers::constructExpr;
+using clang::ast_matchers::defaultArgExpr;
using clang::ast_matchers::expr;
using clang::ast_matchers::forEach;
using clang::ast_matchers::has;
@@ -31,6 +32,7 @@ using clang::ast_matchers::id;
using clang::ast_matchers::methodDecl;
using clang::ast_matchers::newExpr;
using clang::ast_matchers::ofClass;
+using clang::ast_matchers::unless;
using clang::ast_matchers::varDecl;
using clang::tooling::CommonOptionsParser;
using clang::tooling::Replacement;
@@ -105,7 +107,8 @@ void EmptyStringConverter::SetupMatchers(MatchFinder* match_finder) {
"call",
constructExpr(hasDeclaration(methodDecl(ofClass(matchesName(kPattern)))),
argumentCountIs(1),
- hasArgument(0, id("arg", expr()))));
+ hasArgument(0, id("arg", expr())),
+ unless(hasArgument(0, defaultArgExpr()))));
match_finder->addMatcher(varDecl(forEach(constructor_call)),
&constructor_callback_);
diff --git a/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-expected.cc b/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-expected.cc
index 16f3116..8cdb486 100644
--- a/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-expected.cc
+++ b/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-expected.cc
@@ -18,12 +18,16 @@ class TestInitializers {
public:
TestInitializers() {}
TestInitializers(bool) {}
- TestInitializers(double) : b(new int), c() {}
+ TestInitializers(double)
+ : b(new int), c(), f(static_cast<int*>(malloc(sizeof(int)))) {}
private:
scoped_ptr<int> a;
scoped_ptr<int> b;
scoped_ptr<int> c;
+ scoped_ptr_malloc<int> d;
+ scoped_ptr_malloc<int> e;
+ scoped_ptr_malloc<int> f;
};
scoped_ptr<int> TestTemporaries(scoped_ptr<int> a, scoped_ptr<int> b) {
diff --git a/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-original.cc b/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-original.cc
index 4fb3f2e..25c59e0f 100644
--- a/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-original.cc
+++ b/tools/clang/rewrite_scoped_ptr_ctor_null/tests/test-original.cc
@@ -18,13 +18,17 @@ void TestNew() {
class TestInitializers {
public:
TestInitializers() : a(NULL) {}
- TestInitializers(bool) : a(NULL), b(NULL) {}
- TestInitializers(double) : a(NULL), b(new int), c() {}
+ TestInitializers(bool) : a(NULL), b(NULL), e(NULL) {}
+ TestInitializers(double)
+ : a(NULL), b(new int), c(), f(static_cast<int*>(malloc(sizeof(int)))) {}
private:
scoped_ptr<int> a;
scoped_ptr<int> b;
scoped_ptr<int> c;
+ scoped_ptr_malloc<int> d;
+ scoped_ptr_malloc<int> e;
+ scoped_ptr_malloc<int> f;
};
scoped_ptr<int> TestTemporaries(scoped_ptr<int> a, scoped_ptr<int> b) {