Enum parameters for a C++11 Attribute

I tried to include a variadic parameter into a c++11 attribute:

Example:

int main(){

[[my::ownattr(RED, BLUE)]]
f();

}

being A and B values of an enumerate like:
enum class Color {RED, GREEN, BLUE};

Any help?
Thanks.

Regards,
Luis.

What does your attribute's table definition look like? What problems
are you running into?

~Aaron

It is something like that:

file: include/clang/Basic/Attr.td

def OWNmyattr : Attr {
let Spellings = [CXX11<“own”, “myattr”>];

let Args = [VariadicEnumArgument<“Color”, “ColorType”,
[“RED”, “BLUE”,“GREEN”],
[“RED”, “BLUE”,“GREEN”]>];
let Documentation = [Undocumented];
}

Thanks,

Regards,
Luis.

It is something like that:

file: include/clang/Basic/Attr.td

def OWNmyattr : Attr {
let Spellings = [CXX11<“own”, “myattr”>];

let Args = [VariadicEnumArgument<“Color”, “ColorType”,
[“RED”, “BLUE”,“GREEN”],
[“RED”, “BLUE”,“GREEN”]>];
let Documentation = [Undocumented];
}

Thanks,

Regards,
Luis.

It is something like that:

file: include/clang/Basic/Attr.td

def OWNmyattr : Attr {
  let Spellings = [CXX11<"own", "myattr">];
  let Args = [VariadicEnumArgument<"Color", "ColorType",
                           ["RED", "BLUE","GREEN"],
                           ["RED", "BLUE","GREEN"]>];
  let Documentation = [Undocumented];
}

That definition looks reasonable to me; what problems are you running into?

~Aaron

Hey all,

Can someone please let me know what the status of this patch is:

http://clang-developers.42468.n3.nabble.com/OpenCL-patch-support-for-builtin-astype-builtin-convert-builtin-vec-step-td2523963.html

It looks to me like support for both __builtin_astype & vec_step() have been included, but not __builtin_convert?

I need to implement the opencl convert_* functions, and I am trying to determine what open-source support there is for these functions before I start writing the code myself.

Thanks in advance,
Tyler

When I compile this sample:

int main()
{
int a = 5;
int b = 6;
[[own::myattr(RED)]]
auto j5 = 2*a ;
return 0;
}

I have the following message:

$ clang++ test03.cpp -std=c++11 -Xclang -ast-dump -fsyntax-only
test03.cpp:7:19: error: use of undeclared identifier 'RED’
[[own::myattr(RED)]]
^

Using:

def OWNMyattr : Attr {
let Spellings = [CXX11<“own”, “myattr”>];
let Args = [VariadicEnumArgument<“Color”, “ColorType”,
[“RED”, “BLUE”,“GREEN”],
[“RED”, “BLUE”,“GREEN”]>];
let Documentation = [Undocumented];
}

However if I use "RED" instead RED, It compiles.

$clang++ test03.cpp -std=c++11 -Xclang -ast-dump -fsyntax-only
TranslationUnitDecl 0x864a240 <>

-TypedefDecl 0x864a780 <> implicit __int128_t ‘__int128’
-TypedefDecl 0x864a7e0 <> implicit __uint128_t ‘unsigned __int128’
-TypedefDecl 0x864aba0 <> implicit __builtin_va_list ‘__va_list_tag [1]’
-FunctionDecl 0x864ac40 <test03.cpp:3:1, line:10:1> line:3:5 main 'int (void)' -CompoundStmt 0x868e2c8 <line:4:1, line:10:1>
-DeclStmt 0x864adc8 <line:5:5, col:14>
-VarDecl 0x864ad50 <col:5, col:13> col:9 used a 'int' cinit -IntegerLiteral 0x864ada8 col:13 ‘int’ 5
-DeclStmt 0x864ae68 <line:6:5, col:14>
-VarDecl 0x864adf0 <col:5, col:13> col:9 b 'int' cinit -IntegerLiteral 0x864ae48 col:13 ‘int’ 6
-DeclStmt 0x868e270 <line:8:5, col:19>
`-VarDecl 0x868e080 <col:5, col:17> col:10 j5 ‘int’:‘int’ cinit

-BinaryOperator 0x868e188 <col:15, col:17> ‘int’ ‘*’

-IntegerLiteral 0x868e128 col:15 ‘int’ 2
-ImplicitCastExpr 0x868e170 <col:17> 'int' <LValueToRValue> -DeclRefExpr 0x868e148 col:17 ‘int’ lvalue Var 0x864ad50 ‘a’ ‘int’
**-OWNMyattrAttr 0x868e0e0 <line:7:7, col:24>** -ReturnStmt 0x868e2a8 <line:9:5, col:12>
`-IntegerLiteral 0x868e288 col:12 ‘int’ 0

Regards,
Luis.

Hmmm, it seems that variadic enum arguments are strings only, which is
inconsistent with enum arguments which can be strings or identifiers.
I believe that's an an oversight, and have fixed it in r224582.

~Aaron