javaLover
javaLover

Reputation: 6425

What is the meaning of "C4649: attributes are ignored in this context"?

What does this warning mean?

Here is the mcve.

template<class K> class TTT{
    public: alignas(alignof(K)) 
    union{ 
        char raw[sizeof(K)];        
        K rawK;
    }; //<-- error at this line
};

If I compile this single file with ctrl+F7 in Visual Studio 2015, I will get this warning.

warning C4649: attributes are ignored in this context
note: see reference to class template instantiation 'TTT<K>' being compiled

I appear in my computer, but http://rextester.com can't reproduce this warning though.

Other information :-

I can't really find any sites that has some useful description about it.

Has anyone ever encountered it before?

Upvotes: 3

Views: 117

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409176

Reading e.g. this alignas reference it should be placed between the struct or union keyword and the structure/union tag.

So it should be something like

template<class K> struct TTT{
    union alignas(alignof(K)) {
    //    ^^^^^^^^^^^^^^^^^^^
    //    Note placement
        char raw[sizeof(K)];        
        K rawK;
    };
};

Upvotes: 5

Related Questions