diff options
-rw-r--r-- | clang-tools-extra/clangd/Selection.cpp | 6 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/SelectionTests.cpp | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp index 77174936dfe..1877b1cf7b6 100644 --- a/clang-tools-extra/clangd/Selection.cpp +++ b/clang-tools-extra/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 @@ public: 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/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp index e1a103e8a2b..964f0e98e28 100644 --- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -210,6 +210,15 @@ TEST(SelectionTest, CommonAncestor) { )cpp", "FunctionProtoTypeLoc", }, + { + R"cpp( + struct S { + int foo; + int bar() { return [[f^oo]]; } + }; + )cpp", + "MemberExpr", // Not implicit CXXThisExpr! + }, // Point selections. {"void foo() { [[^foo]](); }", "DeclRefExpr"}, |