[cfe-dev] Visual C++ __interface keyword

David Robins llvm at davidrobins.net
Sun Aug 12 16:49:06 PDT 2012


On Sun, Aug 12, 2012 at 03:22:00PM -0700, John McCall wrote:
> Can __interface be used in all the same ways as a standard class-key?
> 
> That is, can you write:
>   __interface foo; // forward declaration
> or
>   __interface foo *ptr = 0; // elaborated type specifier

Yes. However, either 'struct' or 'class' can be used to define class foo
subsequently. Could it still work as an attribute? That seems like a
good way to proceed.

> If so, the right way to model this in the AST is to add it as a new alternative
> to both TypeSpecifierType (in clang/Basic/Specifiers.h) and TagTypeKind
> (in clang/AST/Type.h).  You might have to audit all the places that store the
> latter to make sure they don't stuff it into a 2-bit bitfield.  You'll also have to
> audit all the users to make sure that they do the right thing on the new
> alternative.
> 
> If not, it would be less invasive to model this as an attribute and either
>   (1) make __interface a macro that expands to 'struct [[ms_interface]]' or
>   (2) make the parser recognize the keyword and add the attribute.

Option 2 seems better (vs. having to always #define a macro and the
added expansion layer), and a number of MS-only keywords are already
defined. What's the right point to convert the keyword into "struct" +
attribute?

Looking at Attr.td an attribute with Subjects = [CXXRecord] seems to be
the right place to start; I'll examine how similar attributes are used
through the source.

Thank you for your help.



More information about the cfe-dev mailing list