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

Douglas Gregor dgregor at apple.com
Tue Nov 30 10:06:51 PST 2010


On Nov 30, 2010, at 10:01 AM, Eric Niebler wrote:

> On 11/29/2010 5:54 PM, Eli Friedman wrote:
>> On Mon, Nov 29, 2010 at 1:10 PM, Eric Niebler <eric at boostpro.com> wrote:
>>> So this is ok:
>>> 
>>> __declspec(selectany) int t1 = 4; // OK
>>> 
>>> But this is not:
>>> 
>>> __declspec(selectany) int t2; // ERROR, not initializer
> <snip>
> 
>>> Any ideas how I should handle this?
>> 
>> I think you're looking for Sema::ActOnUninitializedDecl.
> 
> Thanks, Eli. That's worked like a charm. But no good deed goes
> unpunished, so here's my next question.
> 
> I need to be able to handle cases where the "extern" appears on a
> forward declaration, like this:
> 
> extern const int x4;
> const __declspec(selectany) int x4=4;
> 
> If I check the storage class in Sema::ProcessDeclAttributeList, it
> doesn't show up as extern in this case. I need to check the storage
> class somewhere else. Any ideas where?


If you are looking for the presence of the "extern" keyword specifically, you can walk the chain of previous declarations with getPreviousDeclaration() and check for the "extern" storage class.

Or, more likely, it's a question of external linkage, in which case you'll want to use NamedDecl::getLinkage() to check for external linkage.

	- Doug



More information about the cfe-dev mailing list