7

I inherited a C++ project. I'm building in RHEL 5.5 with GCC 4.1.2 via a makefile. The project is huge (hundreds of files) and in general the code is pretty good. However, every so often during compilation I get a GCC warning that says (prefix "/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2"):

/bits/allocator.h: In constructor ‘std::allocator<_Alloc>::allocator() [with _Tp = char]’:
/bits/allocator.h:97: warning: will never be executed
/bits/allocator.h:97: warning: will never be executed
/ext/new_allocator.h: In constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator() [with _Tp = char]’:
/ext/new_allocator.h:65: warning: will never be executed
/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/bits/allocator.h:105: warning: will never be executed
/ext/new_allocator.h: In destructor ‘__gnu_cxx::new_allocator<_Tp>::~new_allocator() [with _Tp = char]’:
/ext/new_allocator.h:72: warning: will never be executed
/bits/allocator.h: In copy constructor ‘std::allocator<_Alloc>::allocator(const std::allocator<_Alloc>&) [with _Tp = char]’:
/bits/allocator.h:100: warning: will never be executed
/bits/allocator.h:99: warning: will never be executed
/ext/new_allocator.h: In copy constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator(const __gnu_cxx::new_allocator<_Tp>&) [with _Tp = char]’:
/ext/new_allocator.h:67: warning: will never be executed
/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/bits/allocator.h:105: warning: will never be executed

It doesn't give me the source file or line number that the error is originating from. I'm going to go out on a limb and say the headers for GCC are just fine, so what is going on here? I've never encountered this particular warning before.

3
  • 1
    Off-topic: googling "warning: will never be executed __gnu_cxx::new_allocator" returned this page as the second result. Head asplode Commented Jan 29, 2013 at 20:42
  • @Bribles and the first result returns a gcc bug indicating that "-Wunreachable-code is broken and has been removed from GCC 4.5.". It is advised to remove this warning option from CXXFLAGS. Commented Jan 29, 2013 at 20:46
  • @harpun Your google-fu is strong! I actually didn't put two and two together and realize the error was the result of a CXXFLAG option. Commented Jan 30, 2013 at 18:17

2 Answers 2

11

According to GCC bug 46158, -Wunreachable-code has always been broken and has been removed since GCC 4.5.

It's very likely that your problem is actually not a problem. (Personally, I'd still consider a newer gcc/g++ unless there are special reasons to use 4.1.2 - it is nearly 6 years old.)

Sign up to request clarification or add additional context in comments.

3 Comments

Upgrading gcc is on the list. I figured getting the project environment setup with a known working configuration was a good first step. I'll be curious to see what other "fun" problems I run into with a gcc upgrade though.
-Wunreachable-code has been listed as a dummy switch since GCC 4.6 (GCC 4.6.0 was released on 2011-03-25).
Though the latest version in the documentation is GCC 4.4.7, before GCC 4.5 (not 4.6). GCC 4.4.7 was released 2012-03-13 (time overlap with the 4.5.x series).
3

Bug report 46158 says at the bottom:

-Wunreachable-code is broken and has been removed from GCC 4.5. Do not use it.

So ignoring the warnings doesn't sound like an entirely bad idea.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.