Skip to content

Commit 3192ecf

Browse files
authored
[CodeComplete] Don't drop ArrayToPointerDecay when doing member completion (#134951)
Fixes #123146. rdar://138851576
1 parent 4005088 commit 3192ecf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5726,7 +5726,10 @@ class ConceptInfo {
57265726
QualType getApproximateType(const Expr *E, HeuristicResolver &Resolver) {
57275727
if (E->getType().isNull())
57285728
return QualType();
5729-
E = E->IgnoreParenImpCasts();
5729+
// Don't drop implicit cast if it's an array decay.
5730+
if (auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5731+
!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay)
5732+
E = E->IgnoreParenImpCasts();
57305733
QualType Unresolved = E->getType();
57315734
// Resolve DependentNameType
57325735
if (const auto *DNT = Unresolved->getAs<DependentNameType>()) {

clang/test/CodeCompletion/member-access.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ void test4(struct Point *p) {
3636
}
3737
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:%(line-3):13 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
3838
// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:%(line-3):23 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
39+
40+
float test5(void) {
41+
struct Point array[4];
42+
return array->x;
43+
}
44+
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-2):17 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
45+
// CHECK-CC4: COMPLETION: x : [#float#]x
46+
// CHECK-CC4: COMPLETION: y : [#float#]y
47+
// CHECK-CC4: COMPLETION: z : [#float#]z

0 commit comments

Comments
 (0)