public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dcb314 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/25808]  New: constant on rhs of conditional assignment
Date: Mon, 16 Jan 2006 14:23:00 -0000	[thread overview]
Message-ID: <bug-25808-9596@http.gcc.gnu.org/bugzilla/> (raw)

Given the following C++ source code 

void g();
void h();

void f( int a, int b)
{
        if (b = 1)      // case 1 - fixed constant on rhs. g() always executed.
                g();
        if (b = a)      // case 2 - variable on rhs. h() might be executed.
                h();
}

then GNU C++ 4.2 snapshot says

dcb@linux:~/C++/Alphasrc> ~/gnu/42-20060114/results/bin/g++ -c -Wall jan15b.cc
jan15b.cc: In function 'void f(int, int)':
jan15b.cc:6: warning: suggest parentheses around assignment used as truth value
jan15b.cc:8: warning: suggest parentheses around assignment used as truth value
dcb@linux:~/C++/Alphasrc>

We can see the compiler fails to distinguish case 1 and case 2.

Suggest enhance the compiler to say something different for case 1.
Fixed constant on rhs is much more likely to be a programmer error, IMHO.

Here is Intel C++ 9.0 doing what I want

jan15b.cc(6): warning #187: use of "=" where "==" may have been intended
        if (b = 1)
            ^


-- 
           Summary: constant on rhs of conditional assignment
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dcb314 at hotmail dot com
  GCC host triplet: x86_64-suse-linux


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


             reply	other threads:[~2006-01-16 14:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-16 14:23 dcb314 at hotmail dot com [this message]
2006-01-16 15:27 ` [Bug c++/25808] " pinskia at gcc dot gnu dot org
2006-01-16 22:28 ` dcb314 at hotmail dot com
2006-01-17 11:51 ` rguenth at gcc dot gnu dot org
2006-03-08  5:09 ` bangerth at dealii dot org

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=bug-25808-9596@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).