[clang] [clang][CodeComplete] Avoid null QualType crash on member access after dependent auto paren-init (PR #249317)
Shengxin Pei via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 5 19:43:37 PST 2026
https://github.com/TPPPP72 created https://github.com/llvm/llvm-project/pull/249317
In uninstantiated templates, direct-initializing an `auto` variable with a dependent expression (`auto x(r[0]);`) can produce a `ParenListExpr` whose approximate type resolves to a null `QualType` via `HeuristicResolver`.
Dereferencing it in `CodeCompleteMemberReferenceExpr` causes an assertion failure in assertion builds and a segfault in release builds.
Skip `ParenListExpr` in `HeuristicResolverImpl::simplifyType`, and add a regression test in `member-access.cpp`.
https://github.com/clice-io/clice/issues/1057#issuecomment-6723994036
>From ba419e8938e8f513c77f11adbf141141effd7ff9 Mon Sep 17 00:00:00 2001
From: Shengxin Pei <TPPPP72 at outlook.com>
Date: Sun, 6 Dec 2026 11:37:11 +0800
Subject: [PATCH] [clang][CodeComplete] Avoid null QualType crash on member
access after dependent auto paren-init
---
clang/lib/Sema/HeuristicResolver.cpp | 10 ++++++++--
clang/test/CodeCompletion/member-access.cpp | 10 ++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index 16a6c8a04d8eb7..4d1b55d33dd48d 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -272,8 +272,14 @@ QualType HeuristicResolverImpl::simplifyType(QualType Type, const Expr *E,
if (T.E && AT->isUndeducedAutoType()) {
if (const auto *DRE = dyn_cast<DeclRefExpr>(T.E)) {
if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
- if (auto *Init = VD->getInit())
- return {resolveExprToType(Init), Init};
+ if (auto *Init = VD->getInit()) {
+ Init = Init->IgnoreImplicit();
+ if (!isa<ParenListExpr>(Init)) {
+ if (QualType InitType = resolveExprToType(Init);
+ !InitType.isNull())
+ return {InitType, Init};
+ }
+ }
}
}
}
diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp
index 2de96b43ff2ba7..dfb436c8fd85f1 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -437,3 +437,13 @@ void f(Alias<T> s) {
// CHECK-TEMPLATE-ALIAS-NESTED: [#int#]b
}
}
+
+namespace dependent_auto_paren_init{
+ template <class T> struct V { T& operator[](int); };
+ template <class T> void f(V<V<T>> r) {
+ auto x(r[0]);
+ x.
+ // RUN: %clang_cc1 -x c++ -fsyntax-only -code-completion-at=%s:445:7 %s -o - | FileCheck -check-prefix=CHECK-AUTO-PAREN-INIT --allow-empty %s
+ // CHECK-AUTO-PAREN-INIT-NOT: COMPLETION:
+ }
+}
More information about the cfe-commits
mailing list