[clang] [Clang] Fix handling of brace ellison when building deduction guides (PR #94889)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 11 07:00:55 PDT 2024
================
@@ -10918,22 +10944,24 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
if (!(RD->getDefinition() && RD->isAggregate()))
return;
QualType Ty = Context.getRecordType(RD);
- SmallVector<QualType, 8> ElementTypes;
-
- InitListChecker CheckInitList(*this, Entity, ListInit, Ty, ElementTypes);
- if (!CheckInitList.HadError()) {
+ auto BuildAggregateDeductionGuide = [&](MutableArrayRef<QualType>
+ ElementTypes,
+ bool BracedVersion = false) {
+ if (ElementTypes.empty())
+ return;
// C++ [over.match.class.deduct]p1.8:
// if e_i is of array type and x_i is a braced-init-list, T_i is an
// rvalue reference to the declared type of e_i and
// C++ [over.match.class.deduct]p1.9:
- // if e_i is of array type and x_i is a bstring-literal, T_i is an
+ // if e_i is of array type and x_i is a string-literal, T_i is an
// lvalue reference to the const-qualified declared type of e_i and
// C++ [over.match.class.deduct]p1.10:
// otherwise, T_i is the declared type of e_i
- for (int I = 0, E = ListInit->getNumInits();
+ for (int I = 0, E = BracedVersion ? ElementTypes.size()
+ : ListInit->getNumInits();
I < E && !isa<PackExpansionType>(ElementTypes[I]); ++I)
if (ElementTypes[I]->isArrayType()) {
- if (isa<InitListExpr>(ListInit->getInit(I)))
+ if (isa<InitListExpr, DesignatedInitExpr>(ListInit->getInit(I)))
----------------
zyn0217 wrote:
I hope I'm reading it correctly. If we look at [`dcl.init.general`](https://eel.is/c++draft/dcl.init.general#nt:braced-init-list), a `braced-init-list` is defined as
```
{ initializer-list, ...}
{ designated-initializer-list, ...}
{ }
```
https://github.com/llvm/llvm-project/pull/94889
More information about the cfe-commits
mailing list