Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ warning: will never be executed

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:

/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]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:97: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:97: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:65: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:105: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In destructor ‘__gnu_cxx::new_allocator<_Tp>::~new_allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:72: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In copy constructor ‘std::allocator<_Alloc>::allocator(const std::allocator<_Alloc>&) [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:100: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:99: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In copy constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator(const __gnu_cxx::new_allocator<_Tp>&) [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:67: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/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.

like image 491
LeviX Avatar asked Jan 29 '13 20:01

LeviX


People also ask

What does mean code has no effect?

Code that has no effect or is never executed (that is, dead or unreachable code) is typically the result of a coding error and can cause unexpected behavior. Such code is usually optimized out of a program during compilation.

How do I make GCC warnings as errors?

The specifier for a warning is appended; for example -Werror=switch turns the warnings controlled by -Wswitch into errors. This switch takes a negative form, to be used to negate -Werror for specific warnings; for example -Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.

What does statement with no effect mean in C?

what does “statement with no effect” mean in c? It means you have a statement in your code that is legal C but does not do anything. The compiler lets you know because it is very likely a mistake on your side. Follow this answer to receive notifications. answered Apr 2, 2021 at 1:34.


2 Answers

According to gcc bug 46158 at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=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.)

like image 148
us2012 Avatar answered Oct 24 '22 21:10

us2012


This bug report http://gcc.gnu.org/bugzilla/show_bug.cgi?id=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.

like image 32
Bribles Avatar answered Oct 24 '22 21:10

Bribles