Bug#123468: gcc: asserts with side effects
Package: gcc
Version: 2:2.95.4-8
Severity: wishlist
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I realize this is probably implemented easily, but a warning about
asserts with obvious side effects would be nice. For example:
assert(ptr = malloc(...)) /* programmer didn't understand/think about assert */
assert(*ptr++) /* ditto */
assert(f()) /* very suspicious */
assert(i = 1) /* programmer made typo */
Some of these may be caught by other warnings (e.g., assignment in
conditional), at least on #undef NDEBUG builds.
The problem with these is, of course, that everything works fine for the
debugging builds.[0] Then you do a release candidate build, and suddenly
everything breaks.
I wouldn't worry about:
#ifndef NDEBUG
...
ptr++
...
#endif
btw, because that looks a lot more guilty to even a novice than
assert(), which looks like a function call.
[0] I'm not sure if assert is allowed to double-use its macro arguments
or not. So its possible that the standard would allow some of the
above to break, even on debugging builds.
- -- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux bohr 2.4.16 #2 SMP Wed Nov 28 05:25:00 EST 2001 i686
Locale: LANG=en_US, LC_CTYPE=en_US
Versions of packages gcc depends on:
ii cpp 2:2.95.4-8 The GNU C preprocessor.
ii cpp-2.95 1:2.95.4-0.011006 The GNU C preprocessor.
ii gcc-2.95 1:2.95.4-0.011006 The GNU C compiler.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE8Flhu5lsmI6uA7bQRAoTfAKCG/Vxgu9c0qW7KCXf7lHethM1iaQCePPqv
w+iRz/SSHiD0T5Q1eA2V6Ww=
=1dtZ
-----END PGP SIGNATURE-----
Reply to: