GDC UDA Attributes (was 'checkedint call removal')

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 2 06:54:31 PDT 2014


On 08/02/14 15:24, Iain Buclaw via Digitalmars-d wrote:
> On 2 August 2014 12:12, Artur Skawina via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> ---------------------------------------------------------------------
>>    static import gcc.attribute;
>>    enum inline = gcc.attribute.attribute("forceinline");
>>
>>    @inline void assert_()(bool c) {
> 
> When I accepted UDA attribute syntax to replace GDC pragmas, I never
> envisioned that this was possible.
> 
> Maybe someone should raise a pull request to add these short-hand
> @attr versions into gcc.attribute?

Are you trying to trick me into contributing to GDC? ;)
Of course I would have done so a long time ago, if not for the
required FSF copyright assignment...

Anyway, this is trivial enough, so...

diff --git a/libphobos/libdruntime/gcc/attribute.d b/libphobos/libdruntime/gcc/attribute.d
index b1c61f10db5b..0098e26c7594 100644
--- a/libphobos/libdruntime/gcc/attribute.d
+++ b/libphobos/libdruntime/gcc/attribute.d
@@ -27,3 +27,7 @@ auto attribute(A...)(A args) if(A.length > 0 && is(A[0] == string))
 {
     return Attribute!A(args);
 }
+
+enum noinline = attribute("noinline");
+enum inline = attribute("forceinline");
+enum flatten = attribute("flatten");

But I'm not sure if exposing `attribute` like that would be
a good idea (until now I was always using a static import, so
name clashes were not a problem); I'd probably rename it to
`__attribute__`.

artur


More information about the Digitalmars-d mailing list