C unsed results warning when optiming

Bug #1837329 reported by Bill Pringlemeir
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-7 (Ubuntu)
New
Undecided
Unassigned

Bug Description

Here is a sample program,

printf "#include <sys/uio.h>\nvoid foo(void) {\n (void)writev(1, (void*)0, 0);\n }\n" | gcc -Wall -Wformat=2 -Wshadow -O1 -c -xc - -o foo.o

If you change to '-O0', there is no warning. I have x86_64 but I doubt that matters? The issue is to have the warnings, but ignore by casting the result for that particular case (next statement is abort()).

The same things happens in 4.8, 4.9, and version 5. Maybe this is desired?

Revision history for this message
Bill Pringlemeir (bpringlemeir2) wrote :

I found the gcc bugzilla thread. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

It is weird that optimization affects the warning?
I was hoping the `(void)` would get rid of it for just this case.

You can close if you believe the optimization should affect the warnings given. Probably the pass to report it is not executed at level 0.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.