[Bug c++/57039] New: -Wsequence-point missing warning for such case

tango_antispams at outlook dot com gcc-bugzilla@gcc.gnu.org
Mon Apr 22 22:37:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57039

             Bug #: 57039
           Summary: -Wsequence-point missing warning for such case
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tango_antispams@outlook.com


Hi,
I think -Wsequence-point should warn for such case:
#include <stdio.h>
int main(int argc, char* argv[])
{
    int color = argc;
    ++color = (color > 3) ? 0 : color;
    printf("argc = %d, color = %d\n", argc, color);
    return 0;
}

With -Wall, no warning at all.
Since the ++ operation and = operation can make real 'color' update in any
order.
(Use "2" or "2 3" or "2 3 4" as parameters and you can see difference:
> ./test
argc = 1, color = 2
> ./test 2
argc = 2, color = 3
> ./test 2 3
argc = 3, color = 0
> ./test 2 3 4
argc = 4, color = 0
)

What is your idea?

Thanks,
Tango


I am testing with such version:
Using built-in specs.
COLLECT_GCC=/pkg/software/gnu/gcc/4.7.2/bin/gcc
COLLECT_LTO_WRAPPER=/afs/amd64_linux24/usr/local/packages/software/gnu/gcc/4.7.2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/pkg/software/gnu/gcc/4.7.2
Thread model: posix
gcc version 4.7.2 (GCC)



More information about the Gcc-bugs mailing list