[cfe-commits] r77556 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h lib/CodeGen/CodeGenTypes.cpp test/CodeGenCXX/virt.cpp

Anders Carlsson andersca at mac.com
Thu Jul 30 08:30:02 PDT 2009


30 jul 2009 kl. 08.28 skrev Douglas Gregor:

>
> On Jul 29, 2009, at 9:07 PM, Anders Carlsson wrote:
>
>>
>>>>
>>>> // If this is a C++ class, lay out the nonvirtual bases.
>>>> -  if (Ctx.getLangOptions().CPlusPlus)
>>>> -    LayoutNonVirtualBases(cast<CXXRecordDecl>(D));
>>>> +  if (Ctx.getLangOptions().CPlusPlus) {
>>>> +    const CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
>>>> +    LayoutVtable(RD);
>>>> +    LayoutNonVirtualBases(RD);
>>>
>>> Why check for c++? Do we get CXXRecordDecl AST in other languages I
>>> wonder?
>>>
>>
>> You don't. You can however get RecordDecls back even in CPlusPlus due
>> to Objective-C.
>
> Oops. There's a lot of Sema code that assumes that if we're in C++,  
> all RecordDecls are really CXXRecordDecls.
>
>> I suggest that we always use dyn_cast<CXXRecordDecl>
>> (D) instead of checking CPlusPlus.
>
>
> At some point, I'm planning to kill off CXXRecordDecl entirely, so  
> that we have one kind of RecordDecl that has all of the C and C++  
> behavior in it. Of course, it will differentiate between C and C++  
> records internally, to save space, but that difference won't be  
> visible outside. This is one of those TODO items that keeps getting  
> pushed down.
>

Yeah, that sounds like a great plan Until then, I think it's better to  
use dyn_cast<CXXRecordDecl> instead of getLang().CPlusPlus (although  
I'll admit to using the latter method at times too :)

Anders




More information about the cfe-commits mailing list