public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25808] New: constant on rhs of conditional assignment
@ 2006-01-16 14:23 dcb314 at hotmail dot com
2006-01-16 15:27 ` [Bug c++/25808] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2006-01-16 14:23 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/25808] constant on rhs of conditional assignment
2006-01-16 14:23 [Bug c++/25808] New: constant on rhs of conditional assignment dcb314 at hotmail dot com
@ 2006-01-16 15:27 ` pinskia at gcc dot gnu dot org
2006-01-16 22:28 ` dcb314 at hotmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-16 15:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2006-01-16 15:27 -------
Both of these are questionable, I don't see why there should be a different
diagnostic.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25808
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/25808] constant on rhs of conditional assignment
2006-01-16 14:23 [Bug c++/25808] New: constant on rhs of conditional assignment dcb314 at hotmail dot com
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
3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2006-01-16 22:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from dcb314 at hotmail dot com 2006-01-16 22:28 -------
(In reply to comment #1)
> Both of these are questionable, I don't see why there should be a different
> diagnostic.
Because the two different diagnostics make it easier to grep for.
For example, Intel C++ compiler finds case 1, but says nothing
about case 2. Easy to grep for.
GNU C++ produces the same message for case 1 and case 2, leading
to a lot of time wasting manual checking of diagnostics.
Surely case 1 is much more likely to be programmer error than case 2 ?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25808
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/25808] constant on rhs of conditional assignment
2006-01-16 14:23 [Bug c++/25808] New: constant on rhs of conditional assignment dcb314 at hotmail dot com
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
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-01-17 11:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2006-01-17 11:51 -------
I agree with Pinskia here - also the detection of a constant RHS is difficult
and
will cause followup PRs that we do not catch all cases.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25808
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/25808] constant on rhs of conditional assignment
2006-01-16 14:23 [Bug c++/25808] New: constant on rhs of conditional assignment dcb314 at hotmail dot com
` (2 preceding siblings ...)
2006-01-17 11:51 ` rguenth at gcc dot gnu dot org
@ 2006-03-08 5:09 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2006-03-08 5:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bangerth at dealii dot org 2006-03-08 05:09 -------
I agree with Richard and Andrew. I don't see why we should issue different
diagnostics for essentially the same case.
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
Status|UNCONFIRMED |RESOLVED
Resolution| |WONTFIX
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25808
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-03-08 5:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-16 14:23 [Bug c++/25808] New: constant on rhs of conditional assignment dcb314 at hotmail dot com
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
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).