[cfe-commits] r71946 - in /cfe/trunk/lib/Sema: SemaDecl.cpp SemaExpr.cpp

Douglas Gregor dgregor at apple.com
Mon May 18 15:14:41 PDT 2009


On May 18, 2009, at 3:11 PM, Eli Friedman wrote:

> On Mon, May 18, 2009 at 3:00 PM, Douglas Gregor <dgregor at apple.com>  
> wrote:
>>
>> On May 18, 2009, at 2:43 PM, Eli Friedman wrote:
>>
>>> On Mon, May 18, 2009 at 11:29 AM, Douglas Gregor <dgregor at apple.com>
>>> wrote:
>>>>>
>>>>> @@ -916,7 +916,13 @@
>>>>>  MergeAttributes(New, Old, Context);
>>>>>
>>>>>  // Merge the types
>>>>> -  QualType MergedT = Context.mergeTypes(New->getType(),
>>>>> Old->getType());
>>>>> +  QualType MergedT;
>>>>> +  if (getLangOptions().CPlusPlus) {
>>>>> +    if (Context.hasSameType(New->getType(), Old->getType()))
>>>>> +      MergedT = New->getType();
>>>>> +  } else {
>>>>> +    MergedT = Context.mergeTypes(New->getType(), Old->getType());
>>>>> +  }
>>>>>  if (MergedT.isNull()) {
>>>>>   Diag(New->getLocation(), diag::err_redefinition_different_type)
>>>>>     << New->getDeclName();
>>>>
>>>> This is slightly too strict in C++, because it's okay to  
>>>> redeclare a
>>>> variable that has an incomplete type with a complete type (and vice
>>>> versa).
>>>> Here's a test case that used to work in C++ but doesn't now:
>>>>
>>>>       extern int array[10];
>>>>       extern int array[];
>>>>       extern int array[10];
>>>
>>> Okay. I can fix it if you want; can you give me a citation for the  
>>> rules?
>>
>> Well, that's interesting: I can't find any wording that makes this  
>> code
>> legal, although both GCC and EDG accept it in their strict  
>> conformance
>> modes.
>
> Hmm, I just tried a bit of searching; [basic.link]p10 seems to allow
> this: "the types specified by all declarations referring to a given
> object or function shall be identical, except that declarations for an
> array object can specify array types that differ by the presence or
> absence of a major array bound".

Good find; I missed that one.

> So I think a reasonable
> implementation would be to allow merging an IncompleteArrayType with a
> ConstantArrayType when the element types are the same.


Yes, agreed.

	- Doug



More information about the cfe-commits mailing list