"C4649:属性在此上下文中被忽略"是什么意思?

jav*_*ver 3 c++ alignment compiler-warnings visual-c++ c++14

这个警告意味着什么?

这是mcve.

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

如果我ctrl+F7在Visual Studio 2015中编译此单个文件,我将收到此警告.

warning C4649: attributes are ignored in this context
note: see reference to class template instantiation 'TTT<K>' being compiled
Run Code Online (Sandbox Code Playgroud)

我出现在我的电脑中,但http://rextester.com无法重现此警告.

其他信息: -

  • 请注意,TTT<K>它从未真正实例化过.
  • 如果我删除了这个词 alignas(alignof(K)),警告就会消失.
  • 对于一些测试用例,这个类实际上是可用的.

我真的找不到任何有关它的有用描述的网站.

有没有人曾经遇到过它?

Som*_*ude 5

读取例如alignas引用应该放在structor union关键字和structure/union标记之间.

所以应该是这样的

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