[clang] [Sema] Fast-path simple plain auto deduction in DeduceAutoType (PR #188196)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 23 07:21:33 PDT 2026
================
@@ -5224,25 +5224,40 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
return TemplateDeductionResult::Success;
}
- auto *InitList = dyn_cast<InitListExpr>(Init);
- bool IsArrayType = Type.getType()->isArrayType();
- if (!getLangOpts().CPlusPlus && (InitList || IsArrayType)) {
- Diag(Init->getBeginLoc(), diag::err_auto_init_list_from_c)
- << (int)AT->getKeyword() << IsArrayType;
- return TemplateDeductionResult::AlreadyDiagnosed;
+ // Make sure that we treat 'char[]' equaly as 'char*' in C23 mode.
+ auto *String = dyn_cast<StringLiteral>(Init);
+ if (getLangOpts().C23 && String && Type.getType()->isArrayType()) {
+ Diag(Type.getBeginLoc(), diag::ext_c23_auto_non_plain_identifier);
+ TypeLoc TL = TypeLoc(Init->getType(), Type.getOpaqueData());
+ Result = SubstituteDeducedTypeTransform(*this, DependentResult).Apply(TL);
+ assert(!Result.isNull() && "substituting DependentTy can't fail");
+ return TemplateDeductionResult::Success;
}
// Emit a warning if 'auto*' is used in pedantic and in C23 mode.
if (getLangOpts().C23 && Type.getType()->isPointerType()) {
Diag(Type.getBeginLoc(), diag::ext_c23_auto_non_plain_identifier);
}
+ auto *InitList = dyn_cast<InitListExpr>(Init);
+ if (!getLangOpts().CPlusPlus && InitList) {
+ Diag(Init->getBeginLoc(), diag::err_auto_init_list_from_c)
+ << (int)AT->getKeyword() << getLangOpts().C23;
+ return TemplateDeductionResult::AlreadyDiagnosed;
+ }
+
// Deduce type of TemplParam in Func(Init)
SmallVector<DeducedTemplateArgument, 1> Deduced;
Deduced.resize(1);
SmallVector<OriginalCallArg, 4> OriginalCallArgs;
+ bool CanTryFastPath =
+ !InitList &&
+ !Init->getType()->isSpecificBuiltinType(BuiltinType::Overload) &&
+ !getLangOpts().ObjC && !getLangOpts().OpenCL;
----------------
mizvekov wrote:
Yes, strong qualifiers is the one kind of conversion we have for type template arguments.
That's gated on the ARC feature: getLangOpts().ObjCAutoRefCount
https://github.com/llvm/llvm-project/pull/188196
More information about the cfe-commits
mailing list