Improve the definition of the brace elision of aggregate initialization
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
[dcl.init.aggr] p16 state
Braces can be elided in an initializer-list as follows. If the initializer-list begins with a left brace, then the succeeding comma-separated list of initializer-clauses initializes the elements of a subaggregate;
Presumably, the initializer-list refers to the initializer-list enclosed in the brace-list-initializer of the aggregate initialization. Consider this example:
struct A{
int a;
};
struct B{
int arr[2];
A obj;
};
int main(){
B b = {0,1,{2}}; // #1
B b2 = {{0,1},2}; //#2
}
In this case, the initializer-list at #1 is 0,1,{2} that does not begin with a left brace.
If, however, the initializer-list for a subaggregate does not begin with a left brace, then only enough initializer-clauses from the list are taken to initialize the elements of the subaggregate;
The initializer-list at #2 is {0,1}, 2 that does begin with a left brace, however, we want the brace elision rule can apply to the initializer-clause 2 when initializing the subaggregate B::obj. In such two cases, we just intend to mean whether the initializer-clause begins with a left brace or not.
Maybe, change [dcl.init.aggr] p16 to
Braces can be elided in an initializer-list as follows. If the initializer-clause in the initializer-list that would initialize the subaggregate element is not a braced-init-list, only enough initializer-clauses from the list are taken to initialize the elements of the subaggregate; the elements are considered to be explicitly initialized. Any remaining initializer-clauses(if any) are left to initialize the next element of the aggregate of which the current subaggregate is an element.
if the initializer-clause is a brace-init-list, I think it is not necessary to specify in this paragraph. That would be redundant since it is just a normal aggregate initialization.
The emphasized wording may be more precise if it is changed to
If the initializer-clause in the initializer-list that would initialize the subaggregate element is not a braced-init-list, only enough initializer-clauses from the list are taken with comma-separation to form an initializer-list D, the subaggregate is initialized by braced-init-list
{ D }
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with [dcl.init.aggr] paragraph 16 and compare its wording with the aggregate-initialization examples #1 and #2 in the issue. Trace how the paragraph describes initializer-lists and initializer-clauses, then determine whether the proposed wording resolves both cases without redundancy. Done means the standard text precisely describes brace elision for both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100