[clang] [clang][CodeComplete] Recurse into the subexpression of deref operator in getApproximateType (PR #93404)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sun May 26 23:45:17 PDT 2024
================
@@ -5680,8 +5680,16 @@ QualType getApproximateType(const Expr *E) {
}
}
if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
- if (UO->getOpcode() == UnaryOperatorKind::UO_Deref)
- return UO->getSubExpr()->getType()->getPointeeType();
+ if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
+ // We recurse into the subexpression because it could be of dependent
+ // type.
+ QualType SubType = getApproximateType(UO->getSubExpr());
+ if (auto Pointee = SubType->getPointeeType(); !Pointee.isNull())
+ return Pointee;
+ // Our caller expects a non-null result, even though the SubType is
+ // supposed to have a pointee.
+ return SubType;
----------------
zyn0217 wrote:
Thanks, I think that makes sense in the case of dereferencing a non-pointer type, which is ill-formed and we probably should offer nothing for completion.
https://github.com/llvm/llvm-project/pull/93404
More information about the cfe-commits
mailing list