Skip to content

Commit 7429950

Browse files
authored
[clang][CodeComplete] Recurse into the subexpression of deref operator in getApproximateType (llvm#93404)
The issue with the previous implementation bc31be7 was that getApproximateType could potentially return a null QualType for a dereferencing operator, which is not what its caller wants.
1 parent 76b9d38 commit 7429950

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5692,8 +5692,15 @@ QualType getApproximateType(const Expr *E) {
56925692
}
56935693
}
56945694
if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
5695-
if (UO->getOpcode() == UnaryOperatorKind::UO_Deref)
5696-
return UO->getSubExpr()->getType()->getPointeeType();
5695+
if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
5696+
// We recurse into the subexpression because it could be of dependent
5697+
// type.
5698+
if (auto Pointee = getApproximateType(UO->getSubExpr())->getPointeeType();
5699+
!Pointee.isNull())
5700+
return Pointee;
5701+
// Our caller expects a non-null result, even though the SubType is
5702+
// supposed to have a pointee. Fall through to Unresolved anyway.
5703+
}
56975704
}
56985705
return Unresolved;
56995706
}

clang/test/CodeCompletion/member-access.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,20 @@ class A {
367367
// CHECK-DEREF-THIS: [#void#]function()
368368
}
369369
};
370+
371+
template <typename Element>
372+
struct RepeatedField {
373+
void Add();
374+
};
375+
376+
template <typename T>
377+
RepeatedField<T>* MutableRepeatedField() {}
378+
379+
template <class T>
380+
void Foo() {
381+
auto& C = *MutableRepeatedField<T>();
382+
C.
383+
}
384+
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:382:5 %s -o - | FileCheck -check-prefix=CHECK-DEREF-DEPENDENT %s
385+
// CHECK-DEREF-DEPENDENT: [#void#]Add()
370386
}

0 commit comments

Comments
 (0)