Commit fafd3075 authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Fix matcher for constructors via an implicit cast

Fix matcher for constructors via an implicit cast so it matches implicit constructor call where the function accepts a reference.

Change-Id: I2e94d7d05536012a24a42fd30e28c7535f1f2ccc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2545851Reviewed-by: default avatarŁukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828886}
parent 5331a45e
...@@ -1101,10 +1101,12 @@ int main(int argc, const char* argv[]) { ...@@ -1101,10 +1101,12 @@ int main(int argc, const char* argv[]) {
// binds the |s.y| expr if it matches the |affected_expr_matcher| above. // binds the |s.y| expr if it matches the |affected_expr_matcher| above.
// //
// See also testcases in tests/affected-expr-original.cc // See also testcases in tests/affected-expr-original.cc
auto implicit_ctor_expr_matcher = implicitCastExpr(has(cxxConstructExpr(allOf( auto implicit_ctor_expr_matcher = cxxConstructExpr(allOf(
anyOf(hasParent(materializeTemporaryExpr()),
hasParent(implicitCastExpr())),
hasDeclaration( hasDeclaration(
cxxConstructorDecl(allOf(parameterCountIs(1), unless(isExplicit())))), cxxConstructorDecl(allOf(parameterCountIs(1), unless(isExplicit())))),
forEachArgumentWithParam(affected_expr_matcher, parmVarDecl()))))); forEachArgumentWithParam(affected_expr_matcher, parmVarDecl())));
match_finder.addMatcher(implicit_ctor_expr_matcher, &affected_expr_rewriter); match_finder.addMatcher(implicit_ctor_expr_matcher, &affected_expr_rewriter);
// |auto| type declarations ========= // |auto| type declarations =========
......
...@@ -289,6 +289,7 @@ class BasicStringPiece { ...@@ -289,6 +289,7 @@ class BasicStringPiece {
}; };
// Test case: // Test case:
void FunctionTakingBasicStringPiece(StringPiece arg) {} void FunctionTakingBasicStringPiece(StringPiece arg) {}
void FunctionTakingBasicStringPieceRef(const StringPiece& arg) {}
class ClassWithImplicitConstructor { class ClassWithImplicitConstructor {
public: public:
...@@ -307,6 +308,11 @@ void foo() { ...@@ -307,6 +308,11 @@ void foo() {
// 'BasicStringPiece<basic_string<char, char_traits<char>, allocator<char>>>') // 'BasicStringPiece<basic_string<char, char_traits<char>, allocator<char>>>')
// for 1st argument // for 1st argument
FunctionTakingBasicStringPiece(my_struct.const_char_ptr.get()); FunctionTakingBasicStringPiece(my_struct.const_char_ptr.get());
FunctionTakingBasicStringPieceRef(my_struct.const_char_ptr.get());
// No rewrite expected.
FunctionTakingBasicStringPiece(StringPiece(my_struct.const_char_ptr));
FunctionTakingBasicStringPieceRef(StringPiece(my_struct.const_char_ptr));
// Expected rewrite - appending: .get(). This is the same scenario as with // Expected rewrite - appending: .get(). This is the same scenario as with
// StringPiece above (except that no templates are present here). // StringPiece above (except that no templates are present here).
......
...@@ -287,6 +287,7 @@ class BasicStringPiece { ...@@ -287,6 +287,7 @@ class BasicStringPiece {
}; };
// Test case: // Test case:
void FunctionTakingBasicStringPiece(StringPiece arg) {} void FunctionTakingBasicStringPiece(StringPiece arg) {}
void FunctionTakingBasicStringPieceRef(const StringPiece& arg) {}
class ClassWithImplicitConstructor { class ClassWithImplicitConstructor {
public: public:
...@@ -305,6 +306,11 @@ void foo() { ...@@ -305,6 +306,11 @@ void foo() {
// 'BasicStringPiece<basic_string<char, char_traits<char>, allocator<char>>>') // 'BasicStringPiece<basic_string<char, char_traits<char>, allocator<char>>>')
// for 1st argument // for 1st argument
FunctionTakingBasicStringPiece(my_struct.const_char_ptr); FunctionTakingBasicStringPiece(my_struct.const_char_ptr);
FunctionTakingBasicStringPieceRef(my_struct.const_char_ptr);
// No rewrite expected.
FunctionTakingBasicStringPiece(StringPiece(my_struct.const_char_ptr));
FunctionTakingBasicStringPieceRef(StringPiece(my_struct.const_char_ptr));
// Expected rewrite - appending: .get(). This is the same scenario as with // Expected rewrite - appending: .get(). This is the same scenario as with
// StringPiece above (except that no templates are present here). // StringPiece above (except that no templates are present here).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment