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

Eric Niebler eric at boostpro.com
Tue Nov 30 10:01:06 PST 2010


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?

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



More information about the cfe-dev mailing list