[cfe-dev] __declspec(selectany): adding an attribute to a declvar

Eric Niebler eric at boostpro.com
Mon Nov 29 13:10:19 PST 2010


Hi. I'm trying to add support for Microsoft's __declspec(selectany) to
the frontend. (Backend stuff will come later.)

I've added the attribute to the AST, but I'm tightening up the checking.
The attribute should only be added to global data initializations that
have external visibility. So this is ok:

  __declspec(selectany) int t1 = 4; // OK

But this is not:

  __declspec(selectany) int t2; // ERROR, not initializer

I add the attribute to the decl in Sema::ProcessDeclAttributeList, where
I can check that the decl is global && (non-const || external). But
checking for an initializer is a problem because the initializer doesn't
get added to the decl until Sema::AddInitializerToDecl, which is called
later.

Any ideas how I should handle this?

Thanks,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com



More information about the cfe-dev mailing list