Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[over.match.class.deduct] The obscure structure of the rule for aggregate deduction #4735

Closed
xmh0511 opened this issue Jul 5, 2021 · 2 comments
Labels
cwg Issue must be reviewed by CWG.

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 5, 2021

In addition, if C is defined and its definition satisfies the conditions for an aggregate class ([dcl.init.aggr]) with the assumption that any dependent base class has no virtual functions and no virtual base classes, and the initializer is a non-empty braced-init-list or parenthesized expression-list, and there are no deduction-guides for C, the set contains an additional function template, called the aggregate deduction candidate, defined as follows. Let X1,...,XN be the elements of the initializer-list or designated-initializer-list of the braced-init-list, or of the expression-list. For each Xi, let ei be the corresponding aggregate element of C or of one of its (possibly recursive) subaggregates that would be initialized by Xi if

  • [1.5] brace elision is not considered for any aggregate element that has a dependent non-array type or an array type with a value-dependent bound, and
  • [1.6] each non-trailing aggregate element that is a pack expansion is assumed to correspond to no elements of the initializer list, and
  • [1.7] a trailing aggregate element that is a pack expansion is assumed to correspond to all remaining elements of the initializer list (if any).

If there is no such aggregate element ei for any Xi, the aggregate deduction candidate is not added to the set. The aggregate deduction candidate is derived as above from a hypothetical constructor C(T1,...,Tn)

  • if ei is of array type and xi is a braced-init-list or string-literal, Ti is an rvalue reference to the declared type of ei
  • otherwise, Ti is the declared type of ei

According to the expound in P2082R1 and the following example, the actual intent seems to be that:
ei is the corresponding aggregate element of C if the aggregate element is a dependent non-array type or an array type with a value-dependent bound. Instead, ei is the corresponding aggregate element of one of C's subaggregates if the brace elision can be considered(i.e, the inverse cases of what the previous sentence says). However, the current appearance of the structure of "if..." seems to have a reverse meaning. Specifically, the rule probably can be read as that

let ei be the corresponding aggregate element of C,
or the corresponding aggregate element one of its (possibly recursive) subaggregates that would be initialized by Xi if

  • [1.5] brace elision is not considered for any aggregate element that has a dependent non-array type or an array type with a value-dependent bound
    [...]

See this example

template<typename T>
struct Test{
    T t[2];
};
int main(){
  Test t{{1,2}};
}

According to the diagnosis of GCC, the candidate set comprises template<class T> Test(T, T)-> Test<T>. The obscure structure can result in this issue.


Issue 2:
Notice the bullet [1.6] and [1.7] in the above rule. It appears to me these bullets should be statements(general rules for aggregate CTAD), why are they placed after the if condition?

@jensmaurer jensmaurer changed the title The obscure structure of the rule for aggregate deduction [over.match.class.deduct] The obscure structure of the rule for aggregate deduction Jul 9, 2021
@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Jul 19, 2021
@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 12, 2021

From the response of the mailing this issue to core language issue, the intent of this rule is saying if the type of the aggregate element is neither a dependent non-array type nor an array type with a value-dependent bound, and the brace elision is considered due to the initializer-list does not begin with a left brace, ei is the corresponding aggregate element of the subaggregate, otherwise, it is the aggregate element. But, such meaning is hard to read from the current wording(structure).

@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. and removed decision-required A decision of the editorial group (or the Project Editor) is required. labels Nov 7, 2023
@jensmaurer
Copy link
Member

Closing in favor of cplusplus/CWG#83.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG.
Projects
None yet
Development

No branches or pull requests

2 participants