Skip to content

Commit bc31be7

Browse files
[clang][CodeComplete] Handle deref operator in getApproximateType (#86466)
This allows completing after `(*this).` in a dependent context. Fixes clangd/clangd#1952
1 parent a6b870d commit bc31be7

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/AST/ExprConcepts.h"
2121
#include "clang/AST/ExprObjC.h"
2222
#include "clang/AST/NestedNameSpecifier.h"
23+
#include "clang/AST/OperationKinds.h"
2324
#include "clang/AST/QualTypeNames.h"
2425
#include "clang/AST/RecursiveASTVisitor.h"
2526
#include "clang/AST/Type.h"
@@ -5678,6 +5679,10 @@ QualType getApproximateType(const Expr *E) {
56785679
return getApproximateType(VD->getInit());
56795680
}
56805681
}
5682+
if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
5683+
if (UO->getOpcode() == UnaryOperatorKind::UO_Deref)
5684+
return UO->getSubExpr()->getType()->getPointeeType();
5685+
}
56815686
return Unresolved;
56825687
}
56835688

clang/test/CodeCompletion/member-access.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,23 @@ namespace function_can_be_call {
348348
T foo(U, V);
349349
};
350350

351-
&S::f
352-
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
351+
void test() {
352+
&S::f
353+
}
354+
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:352:9 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
353355
// CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#T#]foo<<#typename T#>, <#typename U#>>(<#U#>, <#V#>)
354356
}
357+
358+
namespace deref_dependent_this {
359+
template <typename T>
360+
class A {
361+
int field;
362+
363+
void function() {
364+
(*this).field;
365+
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:364:13 %s -o - | FileCheck -check-prefix=CHECK-DEREF-THIS %s
366+
// CHECK-DEREF-THIS: field : [#int#]field
367+
// CHECK-DEREF-THIS: [#void#]function()
368+
}
369+
};
370+
}

0 commit comments

Comments
 (0)