[cfe-dev] Pseudo-functions taking types as arguments - keywords?

Douglas Gregor dgregor at apple.com
Mon Dec 29 10:53:17 PST 2008


On Dec 29, 2008, at 12:41 PM, Chris Lattner wrote:

>
> On Dec 29, 2008, at 9:26 AM, Eli Friedman wrote:
>>
>> In the past, we've just used keywords; as far as I recall, the only
>> cases we've had to deal with so far are sizeof, alignof, and typeof.
>> You're pretty much forced to use keywords, actually, because you'll
>> need a special action to pass the type names to Sema.  If you want to
>> avoid adding 15 Actions, you can probably make a single  
>> ActOnTypeTrait
>> which takes an enum.
>
> Yep, we already have several other builtins that take types (e.g.
> __builtin_types_compatible_p, etc).  These are all handled in the
> parser as language keywords, because they have ad-hoc and weird
> different parsing rules.
>
> Since these are C++ specific builtins, would it make sense to have
> "builtin templates" that handle these?  That way these could just be
> implicitly declared templates and take their arguments as type
> parameters?


GCC has function-like builtins for the type traits, which are  
documented here:

	http://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html

I think it's best to implement these for querying the properties of  
types, rather than invent some new kind of builtin template. If  
sufficiently motivated, one could also implement Microsoft's type  
trait functions (which, IIRC, the GCC builtins were modeled after):

	http://msdn.microsoft.com/en-us/library/ms177194.aspx

	- Doug



More information about the cfe-dev mailing list