aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCodeComplete.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2022-12-14 20:53:18 +0100
committerSam McCall <sam.mccall@gmail.com>2022-12-15 16:10:19 +0100
commit33e3edde44952ed2be44ad00e6cb73208580bb85 (patch)
tree10d28c09e54ade2d12ce7a6b560f81afffee41af /clang/lib/Sema/SemaCodeComplete.cpp
parent5ebdd838fb9c35d1dcc823aaddb1daec10af09e5 (diff)
downloadllvm-33e3edde44952ed2be44ad00e6cb73208580bb85.zip
llvm-33e3edde44952ed2be44ad00e6cb73208580bb85.tar.gz
llvm-33e3edde44952ed2be44ad00e6cb73208580bb85.tar.bz2
[CodeComplete] Complete members of dependent `auto` variables
When the initializer of an `auto` variable is dependent, clang doesn't give the DeclRefExpr a useful dependent type that we can apply heuristics to. However we can dig one up by looking at the initializer. Differential Revision: https://reviews.llvm.org/D140044
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 0745677..2cd679a 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5512,11 +5512,16 @@ private:
// We accept some lossiness (like dropping parameters).
// We only try to handle common expressions on the LHS of MemberExpr.
QualType getApproximateType(const Expr *E) {
+ if (E->getType().isNull())
+ return QualType();
+ E = E->IgnoreParenImpCasts();
QualType Unresolved = E->getType();
- if (Unresolved.isNull() ||
- !Unresolved->isSpecificBuiltinType(BuiltinType::Dependent))
- return Unresolved;
- E = E->IgnoreParens();
+ // We only resolve DependentTy, or undeduced autos (including auto* etc).
+ if (!Unresolved->isSpecificBuiltinType(BuiltinType::Dependent)) {
+ AutoType *Auto = Unresolved->getContainedAutoType();
+ if (!Auto || !Auto->isUndeducedAutoType())
+ return Unresolved;
+ }
// A call: approximate-resolve callee to a function type, get its return type
if (const CallExpr *CE = llvm::dyn_cast<CallExpr>(E)) {
QualType Callee = getApproximateType(CE->getCallee());
@@ -5579,6 +5584,13 @@ QualType getApproximateType(const Expr *E) {
}
}
}
+ // A reference to an `auto` variable: approximate-resolve its initializer.
+ if (const auto *DRE = llvm::dyn_cast<DeclRefExpr>(E)) {
+ if (const auto *VD = llvm::dyn_cast<VarDecl>(DRE->getDecl())) {
+ if (VD->hasInit())
+ return getApproximateType(VD->getInit());
+ }
+ }
return Unresolved;
}