================
@@ -5262,6 +5256,24 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType 
&Result,
 
     DeducedType = getDecltypeForExpr(Init);
     assert(!DeducedType.isNull());
+  } else if (!InitList && !AT->isGNUAutoType() && !AT->isConstrained() &&
+             Context.hasSameType(Type.getType(), Context.AutoDeductTy) &&
+             !Init->getType()->isSpecificBuiltinType(BuiltinType::Overload) &&
+             Init->getType().isCanonical() &&
+             !Init->getType()->isObjCObjectPointerType()) {
+    // Fast-path a subset of plain unconstrained `auto` deduction for
+    // non-init-list cases with canonical initializer types. For these cases,
+    // the deduced type can be computed directly from the initializer type by
+    // removing references, applying array/function decay, and dropping
+    // top-level cv-qualifiers.
+    QualType Ty = Init->getType();
+    Ty = Ty.getNonReferenceType();
+
+    if (Ty->isArrayType() || Ty->isFunctionType())
+      Ty = Context.getDecayedType(Ty);
+
+    Ty = Ty.getLocalUnqualifiedType();
----------------
Sirraide wrote:

```suggestion
    Ty = Ty.getUnqualifiedType();
```
This is assuming we want to allow non-canonical types. Otherwise, I think this 
would give the wrong result for
```c++
using x = const int;
x y = 4;
auto q = y; // Should be 'int', not 'const int'.
```

https://github.com/llvm/llvm-project/pull/188196
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to