public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108155] New: no warning for for (int i = 1; 1 <= 12; ++i)
@ 2022-12-17 13:31 redi at gcc dot gnu.org
  2022-12-17 18:04 ` [Bug c++/108155] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-12-17 13:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108155

            Bug ID: 108155
           Summary: no warning for for (int i = 1; 1 <= 12; ++i)
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
            Blocks: 87403
  Target Milestone: ---

Somehow I typed a 1 instead of i for the loop condition, and so the loop ran
forever.

It seems like we should warn for logical-or-expression that only involves
constant expressions. I don't see why anybody would write `1 != 12` or `x || 1
< y`.

void foo(int) { }

int main()
{
  for (int i = 1; 1 <= 12; ++i)
    foo(i);
}


Even better would be to warn for expressions like `1 < y` where y is not a
constant, but is known to be unchanged by the loop.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

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

* [Bug c++/108155] no warning for for (int i = 1; 1 <= 12; ++i)
  2022-12-17 13:31 [Bug c++/108155] New: no warning for for (int i = 1; 1 <= 12; ++i) redi at gcc dot gnu.org
@ 2022-12-17 18:04 ` pinskia at gcc dot gnu.org
  2022-12-17 18:14 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 18:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108155

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-12-17
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/108155] no warning for for (int i = 1; 1 <= 12; ++i)
  2022-12-17 13:31 [Bug c++/108155] New: no warning for for (int i = 1; 1 <= 12; ++i) redi at gcc dot gnu.org
  2022-12-17 18:04 ` [Bug c++/108155] " pinskia at gcc dot gnu.org
@ 2022-12-17 18:14 ` redi at gcc dot gnu.org
  2022-12-17 18:17 ` pinskia at gcc dot gnu.org
  2024-06-04 12:50 ` dmalcolm at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-12-17 18:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108155

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang and EDG don't warn for this either, so maybe I'm the only person dumb
enough to write this. It still seems useful, if we can define the right
semantics without false positives, but it's not a priority.

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

* [Bug c++/108155] no warning for for (int i = 1; 1 <= 12; ++i)
  2022-12-17 13:31 [Bug c++/108155] New: no warning for for (int i = 1; 1 <= 12; ++i) redi at gcc dot gnu.org
  2022-12-17 18:04 ` [Bug c++/108155] " pinskia at gcc dot gnu.org
  2022-12-17 18:14 ` redi at gcc dot gnu.org
@ 2022-12-17 18:17 ` pinskia at gcc dot gnu.org
  2024-06-04 12:50 ` dmalcolm at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 18:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108155

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> Clang and EDG don't warn for this either, so maybe I'm the only person dumb
> enough to write this. It still seems useful, if we can define the right
> semantics without false positives, but it's not a priority.

No I have accidently written this too before. 
The only false positive I can think of is with macros really.

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

* [Bug c++/108155] no warning for for (int i = 1; 1 <= 12; ++i)
  2022-12-17 13:31 [Bug c++/108155] New: no warning for for (int i = 1; 1 <= 12; ++i) redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-12-17 18:17 ` pinskia at gcc dot gnu.org
@ 2024-06-04 12:50 ` dmalcolm at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2024-06-04 12:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108155

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org

--- Comment #4 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
FWIW -fanalyzer detects the example as of GCC 14:
  https://godbolt.org/z/4Effzrrq9 (C, gcc 14.1)
  https://godbolt.org/z/j8avza7hr (C++, gcc trunk)

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

end of thread, other threads:[~2024-06-04 12:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-17 13:31 [Bug c++/108155] New: no warning for for (int i = 1; 1 <= 12; ++i) redi at gcc dot gnu.org
2022-12-17 18:04 ` [Bug c++/108155] " pinskia at gcc dot gnu.org
2022-12-17 18:14 ` redi at gcc dot gnu.org
2022-12-17 18:17 ` pinskia at gcc dot gnu.org
2024-06-04 12:50 ` dmalcolm 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).