public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/29280] New: misleading warning for assignment used as truth construct @ 2006-09-29 1:17 elanthis at awesomeplay dot com 2006-09-29 4:15 ` [Bug c/29280] " pinskia at gcc dot gnu dot org ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: elanthis at awesomeplay dot com @ 2006-09-29 1:17 UTC (permalink / raw) To: gcc-bugs For code of the form: if (var = 0) gcc recommends adding parentheses around the construct. This is intended to disambiguate code of the form: if (ptr = get_ptr()) by coercing people to write it in the form: if ((ptt = get_ptr()) != NULL) However, in many cases, especially for novice C developers, the code was intended to mean: if (ptr == get_ptr()) or if (var == 0) I'm submitting this bug report because I just saw yet another case of a novice developer posting on a forum that he had been trying to get some code to work, and the code he posted included: if (( var = 0 )) I asked and found that he had done what the gcc warning had kindly suggested, not really understanding what the warning meant. The warning is "warning: suggest parentheses around assignment used as truth value" I suggest several possibilities to improve the situation. The first is to simply alter or expand the warning slightly. Perhaps something like, "warning: use == for testing equality; suggest parentheses around assignment used as truth value" The second is to use two separate warning message with some heuristics to determine which to prefer. For example, an assignment to a constant is very rarely used as a truth value. Code of the form 'if ( var = 0 )' should produce a warning that == must be used to test equality. I won't try to make concrete suggestions on the best set of heuristics for these cases, but that one at least is obvious. I would wager that using any non-function expression in an assignment rvalue as a truth value is very rare; that is, 'if ( (foo = bar) != 0 )' is far rarer than 'if ( (foo = baz()) != 0 )'. -- Summary: misleading warning for assignment used as truth construct Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: elanthis at awesomeplay dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/29280] misleading warning for assignment used as truth construct 2006-09-29 1:17 [Bug c/29280] New: misleading warning for assignment used as truth construct elanthis at awesomeplay dot com @ 2006-09-29 4:15 ` pinskia at gcc dot gnu dot org 2006-09-30 15:20 ` elanthis at awesomeplay dot com 2010-02-21 0:39 ` manu at gcc dot gnu dot org 2 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu dot org @ 2006-09-29 4:15 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from pinskia at gcc dot gnu dot org 2006-09-29 04:15 ------- Actually this warning is clear and I don't think it should be changed. -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|minor |enhancement http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/29280] misleading warning for assignment used as truth construct 2006-09-29 1:17 [Bug c/29280] New: misleading warning for assignment used as truth construct elanthis at awesomeplay dot com 2006-09-29 4:15 ` [Bug c/29280] " pinskia at gcc dot gnu dot org @ 2006-09-30 15:20 ` elanthis at awesomeplay dot com 2010-02-21 0:39 ` manu at gcc dot gnu dot org 2 siblings, 0 replies; 6+ messages in thread From: elanthis at awesomeplay dot com @ 2006-09-30 15:20 UTC (permalink / raw) To: gcc-bugs ------- Comment #2 from elanthis at awesomeplay dot com 2006-09-30 15:20 ------- I only bring it up because I've repeatedly seen novice programmers get confused by the warning. It might be clear to someone who's an experienced C developer, but then, they probably don't really need the warning all that much anyhow. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/29280] misleading warning for assignment used as truth construct 2006-09-29 1:17 [Bug c/29280] New: misleading warning for assignment used as truth construct elanthis at awesomeplay dot com 2006-09-29 4:15 ` [Bug c/29280] " pinskia at gcc dot gnu dot org 2006-09-30 15:20 ` elanthis at awesomeplay dot com @ 2010-02-21 0:39 ` manu at gcc dot gnu dot org 2 siblings, 0 replies; 6+ messages in thread From: manu at gcc dot gnu dot org @ 2010-02-21 0:39 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from manu at gcc dot gnu dot org 2010-02-21 00:38 ------- I agree with the reporter. The warning text suggests what it is actually not the most common solution and it fails miserably in some cases (see PR 25733). -- manu at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |manu at gcc dot gnu dot org Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Keywords| |diagnostic Last reconfirmed|0000-00-00 00:00:00 |2010-02-21 00:38:52 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280 ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-29280-4@http.gcc.gnu.org/bugzilla/>]
* [Bug c/29280] misleading warning for assignment used as truth construct [not found] <bug-29280-4@http.gcc.gnu.org/bugzilla/> @ 2012-04-12 23:08 ` manu at gcc dot gnu.org 2023-09-08 21:30 ` pinskia at gcc dot gnu.org 1 sibling, 0 replies; 6+ messages in thread From: manu at gcc dot gnu.org @ 2012-04-12 23:08 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280 Manuel López-Ibáñez <manu at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |xinliangli at gmail dot com --- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-12 23:07:44 UTC --- *** Bug 52957 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/29280] misleading warning for assignment used as truth construct [not found] <bug-29280-4@http.gcc.gnu.org/bugzilla/> 2012-04-12 23:08 ` manu at gcc dot gnu.org @ 2023-09-08 21:30 ` pinskia at gcc dot gnu.org 1 sibling, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-09-08 21:30 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |markgaleck at gmail dot com --- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> --- *** Bug 111344 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-09-08 21:30 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-09-29 1:17 [Bug c/29280] New: misleading warning for assignment used as truth construct elanthis at awesomeplay dot com 2006-09-29 4:15 ` [Bug c/29280] " pinskia at gcc dot gnu dot org 2006-09-30 15:20 ` elanthis at awesomeplay dot com 2010-02-21 0:39 ` manu at gcc dot gnu dot org [not found] <bug-29280-4@http.gcc.gnu.org/bugzilla/> 2012-04-12 23:08 ` manu at gcc dot gnu.org 2023-09-08 21:30 ` pinskia at gcc dot gnu.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).