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

[dcl.init.aggr]/1 An aggregate can have private or protected data members #2892

Merged
merged 1 commit into from May 23, 2019

Conversation

languagelawyer
Copy link
Contributor

@languagelawyer languagelawyer commented May 22, 2019

if they are not direct, like in the code below:

class B { int i; };      // i is private
struct A : B { int j; }; // but A is still an aggregate

A a = { {}, 1 }; // OK

@jensmaurer
Copy link
Member

So, the superficial argument seems to be that this is just an editorial confusion between direct vs. base-class-recursive non-static data members. Or it could be considered an oversight when default member initializers were made to work with aggregates. @zygoloid, this seems borderline editorial.

@languagelawyer
Copy link
Contributor Author

languagelawyer commented May 22, 2019

it could be considered an oversight when default member initializers were made to work with aggregates

I think default member initializers are not the key here, class B { int i; }; is also fine (updated the PR message). It looks like an oversight when aggregates were allowed to have base classes (http://wg21.link/p0017r1). Note that the definition of aggregate elements says "direct non-static data members". (Also, the proposal for designated initializers (http://wg21.link/p0329r4) speaks about "direct non-static data members".)
Also, the note in [dcl.init.aggr]/1 — "Aggregate initialization does not allow accessing protected and private base class' members" — suggests that the item does mean only direct members.

@zygoloid
Copy link
Member

This seems editorial to me. When we allowed aggregates to have base classes, the design intent was that base classes are just regular aggregate elements like non-static data members, which I think makes it reasonably clear that this wording should be interpreted as applying only to the direct members.

@jensmaurer
Copy link
Member

So, let's apply this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants