[clangd] Fix SelectionTree behavior on implicit 'this'
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@370884 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/Selection.cpp b/clangd/Selection.cpp
index 7717493..1877b1c 100644
--- a/clangd/Selection.cpp
+++ b/clangd/Selection.cpp
@@ -19,6 +19,7 @@
#include "clang/Lex/Lexer.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <string>
@@ -205,6 +206,11 @@
bool dataTraverseStmtPre(Stmt *X) {
if (!X)
return false;
+ // Implicit this in a MemberExpr is not filtered out by RecursiveASTVisitor.
+ // It would be nice if RAV handled this (!shouldTRaverseImplicitCode()).
+ if (auto *CTI = llvm::dyn_cast<CXXThisExpr>(X))
+ if (CTI->isImplicit())
+ return false;
auto N = DynTypedNode::create(*X);
if (canSafelySkipNode(N))
return false;
diff --git a/clangd/unittests/SelectionTests.cpp b/clangd/unittests/SelectionTests.cpp
index e1a103e..964f0e9 100644
--- a/clangd/unittests/SelectionTests.cpp
+++ b/clangd/unittests/SelectionTests.cpp
@@ -210,6 +210,15 @@
)cpp",
"FunctionProtoTypeLoc",
},
+ {
+ R"cpp(
+ struct S {
+ int foo;
+ int bar() { return [[f^oo]]; }
+ };
+ )cpp",
+ "MemberExpr", // Not implicit CXXThisExpr!
+ },
// Point selections.
{"void foo() { [[^foo]](); }", "DeclRefExpr"},