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

Eli Friedman eli.friedman at gmail.com
Mon May 18 15:11:07 PDT 2009


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".  So I think a reasonable
implementation would be to allow merging an IncompleteArrayType with a
ConstantArrayType when the element types are the same.

-Eli




More information about the cfe-commits mailing list