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

Sebastian Redl sebastian.redl at getdesigned.at
Mon Dec 29 11:57:54 PST 2008


On Mon, 29 Dec 2008 13:53:17 -0500, Douglas Gregor <dgregor at apple.com>
wrote:
> On Dec 29, 2008, at 12:41 PM, Chris Lattner wrote:
> 
>>
>> 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.

Well, these traits don't have weird or ad-hoc rules, really. But I get the
drift. I'll do them as keywords.

>>
>> 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?
> 

While the notion of compiler-supplied templates is highly attractive in
general, it doesn't allow compatibility on this low level with GCC.
Nevertheless, CSTs could be used for highly interesting purposes at a later
time, e.g. an experimental implementation of compile-time reflection for
C++ types.

> 
> 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.

That's what I'm doing. This also has the advantage of GCC compatibility in
libraries that have their own traits implementations (like Boost).

> 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
> 

Should be doable. There are only 5 or so that aren't C++/CLI-specific.

Sebastian



More information about the cfe-dev mailing list