[clang-tools-extra] r370884 - [clangd] Fix SelectionTree behavior on implicit 'this'

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 05:15:20 PDT 2019


Author: sammccall
Date: Wed Sep  4 05:15:20 2019
New Revision: 370884

URL: http://llvm.org/viewvc/llvm-project?rev=370884&view=rev
Log:
[clangd] Fix SelectionTree behavior on implicit 'this'

Modified:
    clang-tools-extra/trunk/clangd/Selection.cpp
    clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp

Modified: clang-tools-extra/trunk/clangd/Selection.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.cpp?rev=370884&r1=370883&r2=370884&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Selection.cpp (original)
+++ clang-tools-extra/trunk/clangd/Selection.cpp Wed Sep  4 05:15:20 2019
@@ -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;

Modified: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp?rev=370884&r1=370883&r2=370884&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp Wed Sep  4 05:15:20 2019
@@ -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"},




More information about the cfe-commits mailing list