6

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.

Community
  • 1
  • 1
Panch
  • 1,097
  • 3
  • 12
  • 43

1 Answers1

13

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • 2
    Could you please shed some light on what is anonymous in this `typedef` context. I could not really get anything out of it. That would really help me. – Panch Jun 09 '16 at 16:05
  • 1
    This is global header, I shall not be able to move to a source file. Is there a way to completely disable all warnings for a piece of code, despite compiling with `-Wall -Werror`. I tried `#pragma GCC disagnostic ignored "-Wall"` `#pragma GCC disagnostic ignored "-Werror"` does not help. – Panch Jun 10 '16 at 08:01
  • @Panch: `-Wall` and `-Werror` aren't specific warnings, but `#pragma GCC diagnostic warning -Wxyz` disables the specific warning `xyz`.I think this is `-Wsubobject-linkage`. – MSalters Jun 10 '16 at 08:34
  • you are right. IT is `-Wsubobject-linkage` but unfortunately, the compiler gcc 4.8.2 does not recognize that. may be, should be available in the higher version. Please some one correct me if I'm wrong. – Panch Jun 10 '16 at 08:54
  • 3
    I would advice to be more careful; not just try to silence this warning, it is *for real* -- just the compiler can not tell if there is actual danger or not. The linker really treats anonymous objects as distinct entities on each usage, which can be a lingering danger, once such a type is used with static data, shared over several compilation units and especially with initialisation. I have been bitten quite badly with a variation of that situation.... – Ichthyo Dec 25 '16 at 18:56