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

Eli Friedman eli.friedman at gmail.com
Mon Nov 29 14:54:42 PST 2010


On Mon, Nov 29, 2010 at 1:10 PM, Eric Niebler <eric at boostpro.com> wrote:
> 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?

I think you're looking for Sema::ActOnUninitializedDecl.

-Eli




More information about the cfe-dev mailing list