- Title
- Brace-enclosed initializer for scalar member of aggregate
- Status
- cd1
- Section
- 9.5.2 [dcl.init.aggr]
- Submitter
- Greg Comeau
Created on 2007-05-03.00:00:00 last changed 217 months ago
Messages
Date: 2008-06-15.00:00:00
[Voted into the WP at the June, 2008 meeting as part of paper N2672.]
Date: 2007-10-15.00:00:00
Notes from the October, 2007 meeting: The initializer-list proposal will resolve this issue when it is
adopted.
Date: 2007-07-15.00:00:00
Notes from the July, 2007 meeting: It was noted that implementations differ in their handling of this
construct; however, the issue is long-standing and fairly obscure.
Date: 2022-02-18.07:47:23
C (both C90 and C99) appear to allow a declaration of the form in which the initializer of a scalar member of an aggregate can
itself be brace-enclosed. The relevant wording from the C99
Standard is found in 6.7.8 paragraph 11: and paragraph 16: The “list of initializers” in paragraph 16 must be
a recursive reference to paragraph 11 (that's the only place that
describes how an initialized item gets its value from the
initializer expression), which would thus make the
“brace-enclosed” part of paragraph 11 apply to each of
the initializers in the list in paragraph 16 as well. This appears to be an incompatibility between C and C++:
9.5.2 [dcl.init.aggr] paragraph 11 says, which clearly leaves the impression that only a subaggregate
may be initialized by a brace-enclosed initializer-clause. Either the specification in 9.5.2 [dcl.init.aggr]
should be changed to allow a brace-enclosed initializer of a
scalar member of an aggregate, as in C, or this incompatibility
should be listed in Appendix Clause Annex C [diff].
struct S { int i; } s = { { 5 } };
The initializer for a scalar shall be a single expression,
optionally enclosed in braces.
Otherwise, the initializer for an object that has aggregate or
union type shall be a brace-enclosed list of initializers for the
elements or named members.
If the initializer-list begins with a left brace, then the
succeeding comma-separated list of initializer-clauses
initializes the members of a subaggregate....
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-10-05 00:00:00 | admin | set | status: dr -> cd1 |
| 2008-07-27 00:00:00 | admin | set | messages: + msg1744 |
| 2008-07-27 00:00:00 | admin | set | status: review -> dr |
| 2008-05-18 00:00:00 | admin | set | status: open -> review |
| 2007-10-09 00:00:00 | admin | set | messages: + msg1546 |
| 2007-08-05 00:00:00 | admin | set | messages: + msg1526 |
| 2007-05-03 00:00:00 | admin | create | |