Search code examples
c++visual-c++alignmentc++14compiler-warnings

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 :-

  • Notice that TTT<K> is never really instantiated.
  • If I removed the word alignas(alignof(K)), the warning will disappear.
  • With some test case, this class is practically usable.

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

Has anyone ever encountered it before?


Solution

  • 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;
        };
    };