[cfe-commits] [PATCH][Review request] - Anonymous union/struct redesign

John McCall rjmccall at apple.com
Sat Nov 20 18:36:05 PST 2010


On Nov 20, 2010, at 4:18 PM, John McCall wrote:
>>> @@ -2599,15 +2604,21 @@
>>>    //   In addition, if class T has a user-declared constructor (12.1), every
>>>    //   non-static data member of class T shall have a name different from T.
>>>    for (DeclContext::lookup_result R = Record->lookup(Record->getDeclName());
>>> -         R.first != R.second; ++R.first)
>>> +         R.first != R.second; ++R.first) {
>>>      if (FieldDecl *Field = dyn_cast<FieldDecl>(*R.first)) {
>>> -        if (Record->hasUserDeclaredConstructor() ||
>>> -            !Field->getDeclContext()->Equals(Record)) {
>>> +        if (Record->hasUserDeclaredConstructor()) {
>>> +         Diag(Field->getLocation(), diag::err_member_name_of_class)
>>> +            << Field->getDeclName();
>>> +          break;
>>> +        }
>>> +      }
>>> +      else if (IndirectFieldDecl *Field =
>>> +                    dyn_cast<IndirectFieldDecl>(*R.first)) {
>>>        Diag(Field->getLocation(), diag::err_member_name_of_class)
>>>          << Field->getDeclName();
>>> 
>>> This can be
>>> NamedDecl *D = *R.first;
>>> if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) {
>>>   ...
>>> }
>> 
>> What is needed is:
>>     NamedDecl *D = *R.first;
>>     if ((isa<FieldDecl>(D) && Record->hasUserDeclaredConstructor()) ||
>>         isa<IndirectFieldDecl>(D)) {
> 
> [class.union]p5:
>  The names of the members of an anonymous union shall be distinct from
>  the names of any other entity in the scope in which the anonymous union
>  is declared.
> 
> So this applies equally to indirect fields.

Er, I'm not sure what I was trying to say here.  You're right, the
no-user-declared-constructor exception applies only to fields.  Sorry
about the confusion.

John.



More information about the cfe-commits mailing list