[cfe-dev] How to get custom __declspec using clang API

Aaron Ballman aaron at aaronballman.com
Mon Oct 6 10:18:21 PDT 2014


On Sun, Oct 5, 2014 at 4:19 AM, 翔哥 <15200099141 at qq.com> wrote:
> Hi,
>
>    Recently, I am using clang API using C++ to parse VC in Windows, but I
> want to add new custom attribute(GUN) or __declspec(MS) for somehow adding
> new features to C++ in order to do automatic code generation. Are there
> anything methods(API) or suggestions?‍‍
> The following are my test result:
>
> class  __declspec("test") Test_Class{};
>
> The AST printer result of above code does not contain a clang:Attr, while I
> look inside the 'ParseDecl.cpp', it actually parse the __declspec("test")
> and add it to the AttributeList. How can I get it?‍‍

Unknown attributes are not retained. The declaration parser will
create an AttributeList entry for it, but the semantics engine will
issue an unknown attribute warning and drop the attribute instead of
attaching it to the declaration. We do not currently have a way for
you to retain this information in the AST.

~Aaron




More information about the cfe-dev mailing list