Using 'g++' results in "warning: will never be executed"
Asked Answered
A

2

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.

Activate answered 29/1, 2013 at 20:37 Comment(3)
Off-topic: googling "warning: will never be executed __gnu_cxx::new_allocator" returned this page as the second result. Head asplodeAdditive
@Additive 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.Alcaide
@Alcaide 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.Activate
A
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.)

Aristophanes answered 29/1, 2013 at 20:47 Comment(3)
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.Activate
-Wunreachable-code has been listed as a dummy switch since GCC 4.6 (GCC 4.6.0 was released on 2011-03-25).Larisalarissa
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).Larisalarissa
A
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.

Additive answered 29/1, 2013 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.