public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Matthias Klose <doko@klose.in-berlin.de> To: gcc-gnats@gcc.gnu.org, debian-gcc@lists.debian.org Subject: c++/6905: Suggested g++ warning: changed semantics of conditional expressions Date: Sat, 01 Jun 2002 15:46:00 -0000 [thread overview] Message-ID: <E17EH0S-000799-00@gate.local> (raw) >Number: 6905 >Category: c++ >Synopsis: Suggested g++ warning: changed semantics of conditional expressions >Confidential: no >Severity: non-critical >Priority: low >Responsible: unassigned >State: open >Class: change-request >Submitter-Id: net >Arrival-Date: Sat Jun 01 15:46:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: patrick@chaos.org.uk >Release: 3.1 (Debian) (Debian unstable) >Organization: The Debian Project >Environment: System: Debian GNU/Linux (unstable) Architecture: i686 Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-==============-==============-============================================ ii gcc-3.1 3.1-2 The GNU C compiler. ii g++-3.1 3.1-2 The GNU C++ compiler. ii libstdc++4 3.1-2 The GNU stdc++ library version 3 ii libstdc++4-dev 3.1-2 The GNU stdc++ library version 3 (developmen ii binutils 2.12.90.0.7-1 The GNU assembler, linker and binary utiliti ii libc6 2.2.5-6 GNU C Library: Shared libraries and Timezone host: i386-linux configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1ds2/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=$\(prefix\)/share/man --infodir=$\(prefix\)/share/info --with-gxx-include-dir=$\(prefix\)/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux >Description: [ Reported to the Debian BTS as report #33975. Please CC 33975@bugs.debian.org on replies. Log of report can be found at http://bugs.debian.org/33975 ] This is a suggestion for a warning which would greatly help those converting old C++ programs to g++ and ANSI/ISO standard C++, by helping to detect code which gets a clean compile from a strict compiler, but whose behaviour is different at run time as a result of a change in defined semantics imposed by the standard. An example which g++ already handles very well is the change in the scope of variables declared in a for-init-statement causes g++ to issue clear warnings if an ambiguous case is detected (see the documentation for the `-ffor-scope' option). This case is similar, except that g++ has enforced the now standard interpretation since at least gcc 2.7.2 - namely the change in the scope of a conditional expression with respect to a trailing assignment. This change means that, for example, an expression such as (a ? b : c = d) which originally meant ((a ? b : c) = d) will now be interpreted to mean (a ? b : (c = d)) instead. I suggest that expressions like this, when written without parentheses to assert the author's intent, should trigger a warning if the option `-Wparentheses' is active (whether or not `-ansi' was specified), since it seems to match the description `when operators are nested whose precedence people often get confused about'. Alternatively, since the erroneous interpretation is an anachronism, perhaps `-Wtraditional' would be the appropriate option. An example program follows, with output. I'm using gcc version gcc-3.1 on Debian 3.0. Thanks, Patrick // -------------------------------------------------------------------- #include <stdio.h> int main (void) { int x = 0; if (x = 3) // this assignment will raise a parentheses warning... ; // ...but this dubious conditional expression will not do so int a = 1, b = 2, c = 3, d = 4; x = (a ? b : c = d); // just to prove g++ obeys the standard: printf ("(a ? b : c = d) means %s\n", ((b != 4) ? "(a ? b : (c = d))" : // ansi "((a ? b : c) = d)")); // ancient exit(0); } // -------------------------------------------------------------------- $ g++.3,1 -Wparentheses a.cc && ./a.out a.cc: In function `int main()': a.cc:5: warning: suggest parentheses around assignment used as truth value (a ? b : c = d) means (a ? b : (c = d)) >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted:
reply other threads:[~2002-06-01 22:46 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=E17EH0S-000799-00@gate.local \ --to=doko@klose.in-berlin.de \ --cc=33975@bugs.debian.org \ --cc=debian-gcc@lists.debian.org \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).