How to silence “whose type uses the anonymous namespace [-Werror]” gcc version 4.8.2

夙愿已清 提交于 2020-01-04 06:00:36

问题


In one of my project's header file, the following line is included in a inline method

typedef boost::archive::iterators::transform_width<boost::archive::iterators::binary_from_base64<      boost::archive::iterators::remove_whitespace<std::string::const_iterator>>, 8, 6> Base64ToBin;

When I compile this with gcc 4.8.2 I'm getting the following error:

error: ‘boost::archive::iterators::remove_whitespace<__gnu_cxx::__normal_iterator > >’ has a field ‘boost::archive::iterators::remove_whitespace<__gnu_cxx::__normal_iterator > >::’ whose type uses the anonymous namespace [-Werror]

I'm really hitting hard but could not resolve this issue, also from the link1 and link2 it looks like it is an issue with lower version of gcc. Can somebody suggests how to silence this warning or get over with that. I'm using -Werror flag compilation.


回答1:


This looks like a correct warning. Because the code is in a header, it will be included from multiple files but the anonymous namespace is unique for every file. That means the type doesn't have the same definition everywhere.

Solution: move the relevant code to a .cpp file.



来源:https://stackoverflow.com/questions/37722850/how-to-silence-whose-type-uses-the-anonymous-namespace-werror-gcc-version-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!