Title
Aggregate CTAD, string, and brace elision
Status
c++23
Section
12.2.2.9 [over.match.class.deduct]
Submitter
Jason Merrill

Created on 2020-07-14.00:00:00 last changed 9 months ago

Messages

Date: 2023-02-10.02:22:55

Proposed resolution (approved by CWG 2023-02-09):

Change in 12.2.2.9 [over.match.class.deduct] bullet 1.5 as follows:

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 (9.4.2 [dcl.init.aggr]) if
  • 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, or
    • an array type with a dependent array element type and xi is a string literal; and
  • ...
Date: 2023-02-10.00:03:44

Suggested resolution [SUPERSEDED]:

Change in 12.2.2.9 [over.match.class.deduct] bullet 1.5 as follows:

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 (9.4.2 [dcl.init.aggr]) if
  • 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, or
    • a string literal as the corresponding initializer and that has an array type whose element type is a (possibly cv-qualified) template parameter or is a dependent type specified with a qualified-id whose nested-name-specifier is dependent or with a decltype-specifier; and
  • ...
Date: 2023-02-15.00:00:00

[Accepted as a DR at the February, 2023 meeting.]

Consider:

  template <class T>
  struct A {
    T ar[4];
  };
  A a = { "foo" }; 

Subclause 12.2.2.9 [over.match.class.deduct] bullet 1.5 specifies:

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 (9.4.2 [dcl.init.aggr]) if
  • 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
  • ...

The normative rule does not properly consider arrays with dependent element type, initialized by a string literal. MSVC accepts, gcc and clang reject the example.

History
Date User Action Args
2023-07-16 13:00:43adminsetstatus: open -> c++23
2023-07-16 13:00:43adminsetstatus: dr -> open
2023-02-18 18:43:04adminsetstatus: ready -> dr
2023-02-10 23:01:52adminsetstatus: tentatively ready -> ready
2023-02-10 02:22:55adminsetstatus: review -> tentatively ready
2023-02-09 03:12:55adminsetmessages: + msg7180
2023-02-09 03:12:55adminsetstatus: open -> review
2023-01-15 15:49:37adminsetmessages: + msg7140
2020-07-14 00:00:00admincreate