diff options
author | Sam McCall <sam.mccall@gmail.com> | 2019-09-04 12:15:20 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2019-09-04 12:15:20 +0000 |
commit | 3d79fd6fcc8a077d5779bd7987425878dc07ffe7 (patch) | |
tree | fe0debf464b81f9e48f4030395c472efd8b1ff70 | |
parent | 358b80b34017ddabe6eabe8224408d58e7780a88 (diff) | |
download | bcm5719-llvm-3d79fd6fcc8a077d5779bd7987425878dc07ffe7.tar.gz bcm5719-llvm-3d79fd6fcc8a077d5779bd7987425878dc07ffe7.zip |
[clangd] Fix SelectionTree behavior on implicit 'this'
llvm-svn: 370884
-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"}, |