[Bug c/53064] New: -Wsenquence-point behaves inconsistently

2012-04-21 Thread wenbin816 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53064

 Bug #: 53064
   Summary: -Wsenquence-point behaves inconsistently
Classification: Unclassified
   Product: gcc
   Version: 4.7.0
Status: UNCONFIRMED
  Severity: minor
  Priority: P3
 Component: c
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: wenbin...@gmail.com


This is my first bug report here, so please bear with me.

Compiling the following code

int f(int a)
{
  return 0;
}
main()
{
  int a = 0;
  a + f(++a ? 0 : 0);
}

with -Wall gives
test.c:8:9: warning: operation on ‘a’ may be undefined [-Wsequence-point]

while compiling

main()
{
  int a = 0;
  a + (++a ? 0 : 0);
}

with -Wall produces no warning about sequence points.

I think (not sure though) both are UB.

gcc -v information:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.7-20120414/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id
--with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold
--enable-ld=default --enable-plugin --with-plugin-ld=ld.gold
--with-linker-hash-style=gnu --disable-multilib --disable-libssp
--disable-build-with-cxx --disable-build-poststage1-with-cxx
--enable-checking=release
Thread model: posix
gcc version 4.7.0 20120414 (prerelease) (GCC) 

Sorry if the bug is invalid, or if my English is poor.


[Bug c/53064] -Wsequence-point behaves inconsistently

2012-04-21 Thread wenbin816 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53064

Wenbin Lv  changed:

   What|Removed |Added

   Severity|minor   |trivial


[Bug c/53064] -Wsequence-point behaves inconsistently

2012-04-25 Thread wenbin816 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53064

--- Comment #3 from Wenbin Lv  2012-04-25 14:56:48 
UTC ---
(In reply to comment #1)
> >  a + (++a ? 0 : 0);
> 
> Hmm, I don't think there is a sequence point issue here compared to the other
> case where it might cause an undefined code.
> 
> (++a ? 0 : 0) is all in done in one sequence point so that is defined and then
> added to a.  a might be accessed before or after the sequence point where a is
> modified but there is a sequence point between the access and the 
> modification.

Sorry I don't quite understand your reply. Did you mean there are sequence
points before and after evaluation of (++a ? 0 : 0) (my best guess)? If so,
please note that extra parentheses do not import extra sequence points; the C
standard only guarantees that there is a sequence point between the evaluations
of the first and the second (or third) operands of the conditional operator.

And what confuses me is that the first expression seems to have all the
sequence points that the second have, plus another one between the evaluation
of argument and the function call, but is said to be undefined.