Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No completions offered after (*this). in template class #1952

Closed
HighCommander4 opened this issue Feb 29, 2024 · 2 comments · Fixed by llvm/llvm-project#86466
Closed

No completions offered after (*this). in template class #1952

HighCommander4 opened this issue Feb 29, 2024 · 2 comments · Fixed by llvm/llvm-project#86466
Assignees
Labels
bug Something isn't working

Comments

@HighCommander4
Copy link

In the following code:

template <typename T>
class Foo {
  void method1() {
    (*this).^
  }
  void method2() {}
};

code completion at the ^ does not offer members of the class.

It works with this-> and in non-template classes.

@HighCommander4 HighCommander4 added the bug Something isn't working label Feb 29, 2024
@HighCommander4
Copy link
Author

This seems to be enough to fix it:

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c44be0df9b0a..0e44b0f444ed 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OperationKinds.h"
 #include "clang/AST/QualTypeNames.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
@@ -5674,6 +5675,11 @@ QualType getApproximateType(const Expr *E) {
         return getApproximateType(VD->getInit());
     }
   }
+  if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
+    if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
+      return UO->getSubExpr()->getType()->getPointeeType();
+    }
+  }
   return Unresolved;
 }

@HighCommander4 HighCommander4 self-assigned this Mar 25, 2024
HighCommander4 added a commit to HighCommander4/llvm-project that referenced this issue Mar 25, 2024
This allows completing after `(*this).` in a dependent context.

Fixes clangd/clangd#1952
@HighCommander4
Copy link
Author

I put the fix + a test up at llvm/llvm-project#86466

HighCommander4 added a commit to HighCommander4/llvm-project that referenced this issue Mar 26, 2024
This allows completing after `(*this).` in a dependent context.

Fixes clangd/clangd#1952
HighCommander4 added a commit to llvm/llvm-project that referenced this issue Mar 26, 2024
…6466)

This allows completing after `(*this).` in a dependent context.

Fixes clangd/clangd#1952
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant