public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended
@ 2004-10-12 14:15 trt at acm dot org
  2004-10-12 14:19 ` [Bug c/17946] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: trt at acm dot org @ 2004-10-12 14:15 UTC (permalink / raw)
  To: gcc-bugs

People sometimes code "a && MASK" when they intended "a & MASK".
It would be good if gcc issued a warning for suspect cases.

-- 
           Summary: wanted: warning for "a && MASK" when "a & MASK" was
                    probably intended
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: trt at acm dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
@ 2004-10-12 14:19 ` pinskia at gcc dot gnu dot org
  2004-10-12 14:27 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-12 14:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-12 14:19 -------
I the only way this can be done right is not to warn about a && 1 as people sometimes do that 
(especially with macros) and that shows up in GCC a huge amount.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
  2004-10-12 14:19 ` [Bug c/17946] " pinskia at gcc dot gnu dot org
@ 2004-10-12 14:27 ` pinskia at gcc dot gnu dot org
  2004-10-12 14:45 ` trt at acm dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-12 14:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-12 14:27 -------
Really we should not warn because we could be doing a && CONST where we want CONST to be 
compared against 0 so this is invalid.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
  2004-10-12 14:19 ` [Bug c/17946] " pinskia at gcc dot gnu dot org
  2004-10-12 14:27 ` pinskia at gcc dot gnu dot org
@ 2004-10-12 14:45 ` trt at acm dot org
  2004-10-12 16:08 ` bangerth at dealii dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: trt at acm dot org @ 2004-10-12 14:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2004-10-12 14:45 -------
Patch here: http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00990.html

This patch does not warn about "a && 1" for the reason noted in comment #1. 
Some mistakes will go unwarned, but it still catches quite a lot.

The concern expressed in comment #2 is quite plausible, but I have not found it
to be an issue in practice.  e.g. A gcc "make bootstrap" never triggers this
warning.

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (2 preceding siblings ...)
  2004-10-12 14:45 ` trt at acm dot org
@ 2004-10-12 16:08 ` bangerth at dealii dot org
  2004-10-12 18:52 ` trt at acm dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-10-12 16:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-10-12 16:07 -------
If this is put under a flag of its own, it may actually be useful. I 
see no reason why we should dismiss it that quickly. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (3 preceding siblings ...)
  2004-10-12 16:08 ` bangerth at dealii dot org
@ 2004-10-12 18:52 ` trt at acm dot org
  2004-10-14 14:31 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: trt at acm dot org @ 2004-10-12 18:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2004-10-12 18:52 -------
Given the problem pointed out in
http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01013.html I do not see how this
patch can be readily made to work.  To avoid redundant truthvalue conversion it
might be necessary e.g. to change "enum tree_code original_code" to "tree
original_value" in c-tree.h with related changes to c-parse.in and c-typeck.c.
That might be justifiable for other reasons, but probably not this one.

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (4 preceding siblings ...)
  2004-10-12 18:52 ` trt at acm dot org
@ 2004-10-14 14:31 ` pinskia at gcc dot gnu dot org
  2004-10-14 15:54 ` trt at acm dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-14 14:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-14 14:31 -------
I still say that people do have a && 4 in their code meaning a != 0 && 4 !=0.  Also a & 1 should be 
caught too but that would just give too many false postives so there is no way for GCC to warn about 
this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (5 preceding siblings ...)
  2004-10-14 14:31 ` pinskia at gcc dot gnu dot org
@ 2004-10-14 15:54 ` trt at acm dot org
  2004-10-14 17:33 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: trt at acm dot org @ 2004-10-14 15:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2004-10-14 15:54 -------
> a && 4 in their code meaning a != 0 && 4 !=0

That happens, but when it does `a' is not integer type. I use a gcc with this
warning on a 35Mloc code base. There are currently 4 warnings, all pointing to
real bugs.

This is an excellent warning, it just doesn't fit neatly into the gcc front end.

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (6 preceding siblings ...)
  2004-10-14 15:54 ` trt at acm dot org
@ 2004-10-14 17:33 ` bangerth at dealii dot org
  2004-10-15  0:37 ` giovannibajo at libero dot it
  2004-12-08 18:48 ` trt at acm dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-10-14 17:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-10-14 17:33 -------
Andrew, I'm getting angry when you selfishly close PRs that other people 
think are useful to be kept open. The submitter of this PR has shown that 
the cases you claim exist are not frequent, and that they often enough 
point to real bugs. What more proof do you want that you argument is 
wrong? This is, after all, an enhancement request, not a bug report. If 
your code wrongly triggers this warning, just switch it off. 
 
I would also like to remind you that we work based on consensus. If you 
disagree with decisions by others, then that's fine, but you may not put 
your opinions over those of others. If you close a PR and I reopen it, 
don't close it again or we will have to discuss this on the bugmaster 
mailing list. I consider your behavior disrespectful and rude. 
 
Thanks 
  Wolfgang 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (7 preceding siblings ...)
  2004-10-14 17:33 ` bangerth at dealii dot org
@ 2004-10-15  0:37 ` giovannibajo at libero dot it
  2004-12-08 18:48 ` trt at acm dot org
  9 siblings, 0 replies; 11+ messages in thread
From: giovannibajo at libero dot it @ 2004-10-15  0:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-10-15 00:37 -------
I will confirm this because I agree with the submitter, this looks like a good 
warning to use. It would be great if the conflict with the other warning can be 
solved.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-15 00:37:05
               date|                            |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17946] wanted: warning for "a && MASK" when "a & MASK" was probably intended
  2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
                   ` (8 preceding siblings ...)
  2004-10-15  0:37 ` giovannibajo at libero dot it
@ 2004-12-08 18:48 ` trt at acm dot org
  9 siblings, 0 replies; 11+ messages in thread
From: trt at acm dot org @ 2004-12-08 18:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2004-12-08 18:48 -------
I should mention there is a hack for the problem noted in comment #5: do the
temporary truthvalue conversions with warnings suppressed.
That is, change the two instances of

   tree t = lang_hooks.truthvalue_conversion (default_conversion ($1.value));

to instead be

   tree t;
   inhibit_warnings++;
   t = lang_hooks.truthvalue_conversion (default_conversion ($1.value));
   inhibit_warnings--;

So, this can be "readily made to work" after all.  But ugh.

-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-12-08 18:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-12 14:15 [Bug c/17946] New: wanted: warning for "a && MASK" when "a & MASK" was probably intended trt at acm dot org
2004-10-12 14:19 ` [Bug c/17946] " pinskia at gcc dot gnu dot org
2004-10-12 14:27 ` pinskia at gcc dot gnu dot org
2004-10-12 14:45 ` trt at acm dot org
2004-10-12 16:08 ` bangerth at dealii dot org
2004-10-12 18:52 ` trt at acm dot org
2004-10-14 14:31 ` pinskia at gcc dot gnu dot org
2004-10-14 15:54 ` trt at acm dot org
2004-10-14 17:33 ` bangerth at dealii dot org
2004-10-15  0:37 ` giovannibajo at libero dot it
2004-12-08 18:48 ` trt at acm 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).