[CodeComplete] Don't drop ArrayToPointerDecay when doing member completion (#134951)

Fixes https://github.com/llvm/llvm-project/issues/123146.

rdar://138851576
This commit is contained in:
Akira Hatanaka
2025-04-15 10:12:18 -07:00
committed by GitHub
parent 40050888a1
commit 3192ecfa89
2 changed files with 13 additions and 1 deletions

View File

@@ -5726,7 +5726,10 @@ private:
QualType getApproximateType(const Expr *E, HeuristicResolver &Resolver) {
if (E->getType().isNull())
return QualType();
E = E->IgnoreParenImpCasts();
// Don't drop implicit cast if it's an array decay.
if (auto *ICE = dyn_cast<ImplicitCastExpr>(E);
!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay)
E = E->IgnoreParenImpCasts();
QualType Unresolved = E->getType();
// Resolve DependentNameType
if (const auto *DNT = Unresolved->getAs<DependentNameType>()) {

View File

@@ -36,3 +36,12 @@ void test4(struct Point *p) {
}
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:%(line-3):13 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:%(line-3):23 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
float test5(void) {
struct Point array[4];
return array->x;
}
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-2):17 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4: COMPLETION: x : [#float#]x
// CHECK-CC4: COMPLETION: y : [#float#]y
// CHECK-CC4: COMPLETION: z : [#float#]z