[clang] 04ed532 - Fix skip-invisible with overloaded method calls

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 04:37:14 PDT 2020


Author: Stephen Kelly
Date: 2020-05-24T12:36:16+01:00
New Revision: 04ed532ef0ce76d53ca456cbc581756bb01d30e7

URL: https://github.com/llvm/llvm-project/commit/04ed532ef0ce76d53ca456cbc581756bb01d30e7
DIFF: https://github.com/llvm/llvm-project/commit/04ed532ef0ce76d53ca456cbc581756bb01d30e7.diff

LOG: Fix skip-invisible with overloaded method calls

Added: 
    

Modified: 
    clang/lib/AST/Expr.cpp
    clang/unittests/AST/ASTTraverserTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index f173c2408866..0184140ab07e 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2931,8 +2931,10 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
         continue;
       }
       if (auto *PE = dyn_cast<ParenExpr>(ExprNode)) {
-        E = PE;
-        continue;
+        if (PE->getSourceRange() == C->getSourceRange()) {
+          E = PE;
+          continue;
+        }
       }
       ExprNode = ExprNode->IgnoreParenImpCasts();
       if (ExprNode->getSourceRange() == SR)

diff  --git a/clang/unittests/AST/ASTTraverserTest.cpp b/clang/unittests/AST/ASTTraverserTest.cpp
index f56a49bf8e51..affbbe76f0d2 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -265,6 +265,9 @@ TEST(Traverse, IgnoreUnlessSpelledInSourceVars) {
 struct String
 {
     String(const char*, int = -1) {}
+
+    int overloaded() const;
+    int& overloaded();
 };
 
 void stringConstruct()
@@ -273,6 +276,12 @@ void stringConstruct()
     s = "bar";
 }
 
+void overloadCall()
+{
+   String s = "foo";
+   (s).overloaded();
+}
+
 struct C1 {};
 struct C2 { operator C1(); };
 
@@ -331,6 +340,46 @@ FunctionDecl 'stringConstruct'
 )cpp");
   }
 
+  {
+    auto FN =
+        ast_matchers::match(functionDecl(hasName("overloadCall")).bind("fn"),
+                            AST->getASTContext());
+    EXPECT_EQ(FN.size(), 1u);
+
+    EXPECT_EQ(dumpASTString(TK_AsIs, FN[0].getNodeAs<Decl>("fn")),
+              R"cpp(
+FunctionDecl 'overloadCall'
+`-CompoundStmt
+  |-DeclStmt
+  | `-VarDecl 's'
+  |   `-ExprWithCleanups
+  |     `-CXXConstructExpr
+  |       `-MaterializeTemporaryExpr
+  |         `-ImplicitCastExpr
+  |           `-CXXConstructExpr
+  |             |-ImplicitCastExpr
+  |             | `-StringLiteral
+  |             `-CXXDefaultArgExpr
+  `-CXXMemberCallExpr
+    `-MemberExpr
+      `-ParenExpr
+        `-DeclRefExpr 's'
+)cpp");
+
+    EXPECT_EQ(dumpASTString(TK_IgnoreUnlessSpelledInSource,
+                            FN[0].getNodeAs<Decl>("fn")),
+              R"cpp(
+FunctionDecl 'overloadCall'
+`-CompoundStmt
+  |-DeclStmt
+  | `-VarDecl 's'
+  |   `-StringLiteral
+  `-CXXMemberCallExpr
+    `-MemberExpr
+      `-DeclRefExpr 's'
+)cpp");
+  }
+
   {
     auto FN = ast_matchers::match(
         functionDecl(hasName("conversionOperator"),


        


More information about the cfe-commits mailing list