This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/25808] New: constant on rhs of conditional assignment
- From: "dcb314 at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jan 2006 14:23:28 -0000
- Subject: [Bug c++/25808] New: constant on rhs of conditional assignment
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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