| Germinx (7) | |||||
|
Hello community. I'm using g++ with the -Wunreachable-code and the Here is the code:
And here is the output I get:
Is my code wrong? Is a bug in the header file? Is a false positive? Why there is a statement that will never be executed? I have searched the web but I haven't found an answer easily. If someone could help me I would be very pleased. OS: Debian GNU/Linux 6.0.4 (squeeze) Installed packages: g++-4.4 (4.4.5-8) libstdc++6-4.4-dev (4.4.5-8) Thanks in advance and escuse me by my poor English. Germinx. | |||||
|
Last edited on
|
|||||
| kbw (5374) | |
|
The optimiser may drop some of your code, in which case it'll tell you wtih -Wunreachable-code. But if you then tell the compiler to treat warnings as errors with -Wfatal-errors, then it'll treat the warning as an error and stop. http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html | |
|
|
|
| Germinx (7) | ||
First of all thanks for your gentile answer. I knew that -Werror (I made a mistake in my first post and I wrote -Wfatal-errors when it should say -Werror) converts warnings into errors (stopping the compiler). That is intentional to force me to fix any warning before continue coding. What I didn't know was that the dropping was induced by the optimization process. (Thanks a lot for the clarification.) But I would be interested in knowing how can avoid that dropping not in knowing how can avoid that warning. If I would like to turn off that warning I could use: #pragma GCC diagnostic ignored "-Wunreachable-code" But I don't want to do that. I don't want to hide the warning. I would like to safely fix the problem in: /usr/include/c++/4.4/bits/basic_string.h:2147I'm sorry but I didn't explain that well the first time. Best regards Germinx. | ||
|
Last edited on
|
||
| kbw (5374) | |
|
Typically you'll get that warning with an optimised compile. It's not confined to GCC either, other C/C++ compilers emit that warning under similar circumstances. If you got this warning with a debug build, then you really should take a look at the code as there will almost certainly be an issue. | |
|
|
|
| Germinx (7) | |
|
How could I make that debug build? With the -g -O0 options? or are you talking about another thing? With that options I still have the warnings. | |
|
|
|
| kbw (5374) | |
| -g should suffice. | |
|
|
|
| Germinx (7) | |
|
Warnings are still there with a debug build. Looking at the sources makes me think that it could be caused by code that is selectable at compile-time. Though I'm not really sure and I don't know how to safely remove unused parts. Conclusion: My code is fine. It isn't a bug in the header. It isn't a false positive. Thanks a lot for your interest and your time. Germinx. | |
|
Last edited on
|
|