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

Douglas Gregor dgregor at apple.com
Mon May 18 15:00:11 PDT 2009


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.

   - Doug



More information about the cfe-commits mailing list