[clang] [Clang] Fix handling of brace ellison when building deduction guides (PR #94889)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 12 12:36:07 PDT 2024
================
@@ -1449,7 +1449,10 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
// dependent non-array type or an array type with a value-dependent
// bound
assert(AggrDeductionCandidateParamTypes);
- if (!isa_and_nonnull<ConstantArrayType>(
+ // Don't consider the brace elision if the initializer is a
+ // braced-init-list.
+ if (isa<InitListExpr, DesignatedInitExpr>(expr) ||
----------------
hokein wrote:
I think this code does the right thing, to make sure my understanding of the code is correct.
Given the example
```
template <class T> struct Foo {
T t[2];
};
Foo t = {{1, 2}};
```
The `x1` is a brace-init-list `{1, 2}`, the corresponding `e1` is `T t[2]`, as the `e1` has a dependent type we can't perform semantic checks to see whether the `T t[2]` can be initialized by `x1`, we always assume true here. (This has an effect that we will generate the deduction guide even for invalid case e.g. `x1` is `{1, 2, 3}`, but this is fine as this code will be reject during template instantiation afterwards.)
If my understanding is right, can you rephrase the comment `Don't consider the brace elision if the initializer is a braced-init-list.`? Readers can be easily confused with the comment above on L1447 (both are saying brace elision, but they are different).
https://github.com/llvm/llvm-project/pull/94889
More information about the cfe-commits
mailing list