public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser
@ 2012-01-29 23:14 mans at mansr dot com
  2012-01-29 23:57 ` [Bug c/52050] " steven at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: mans at mansr dot com @ 2012-01-29 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52050
           Summary: -Wdeclaration-after-statement does not warn on
                    declaration in for loop initialiser
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mans@mansr.com


Consider this code:

void foo(void)
{
    for (int i = 0; i < 2; i++);
}

Compiling the above code with -std=c99 -Wdeclaration-after-statement
does not produce a warning as expected.


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

* [Bug c/52050] -Wdeclaration-after-statement does not warn on declaration in for loop initialiser
  2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
@ 2012-01-29 23:57 ` steven at gcc dot gnu.org
  2012-01-30  0:11 ` mans at mansr dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: steven at gcc dot gnu.org @ 2012-01-29 23:57 UTC (permalink / raw)
  To: gcc-bugs

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

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-29
     Ever Confirmed|0                           |1

--- Comment #1 from Steven Bosscher <steven at gcc dot gnu.org> 2012-01-29 23:26:47 UTC ---
Yup. Also fails for me with GCC 4.3.2 and GCC 4.1.1. I don't have anything
older available.


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

* [Bug c/52050] -Wdeclaration-after-statement does not warn on declaration in for loop initialiser
  2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
  2012-01-29 23:57 ` [Bug c/52050] " steven at gcc dot gnu.org
@ 2012-01-30  0:11 ` mans at mansr dot com
  2012-01-30  7:15 ` [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mans at mansr dot com @ 2012-01-30  0:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Mans Rullgard <mans at mansr dot com> 2012-01-29 23:34:12 UTC ---
I tested and found it failing with 3.4.6, 4.1.2, 4.2.4, 4.3.6, 4.4.6, 4.5.3,
and 4.6.2.


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

* [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements.
  2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
  2012-01-29 23:57 ` [Bug c/52050] " steven at gcc dot gnu.org
  2012-01-30  0:11 ` mans at mansr dot com
@ 2012-01-30  7:15 ` pinskia at gcc dot gnu.org
  2012-01-30  7:23 ` mans at mansr dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-30  7:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Summary|-Wdeclaration-after-stateme |Want an option to warn
                   |nt does not warn on         |about a declaration inside
                   |declaration in for loop     |a for/while/if statements.
                   |initialiser                 |

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-30 00:36:54 UTC ---
I think -Wdeclaration-after-statement would the wrong option really.  
The declaration in "for (int i = 0; i < 2; i++)" is not after a statement.  I
would think we should have a different warning option for this.  Also the
warning option is there mostly to warn as we turn on this extension by default
for GNU C90 while the declaration inside a for loop support is not turned on
for GNU C90.


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

* [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements.
  2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
                   ` (2 preceding siblings ...)
  2012-01-30  7:15 ` [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements pinskia at gcc dot gnu.org
@ 2012-01-30  7:23 ` mans at mansr dot com
  2012-01-30  9:28 ` rguenth at gcc dot gnu.org
  2023-05-20  4:19 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mans at mansr dot com @ 2012-01-30  7:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Mans Rullgard <mans at mansr dot com> 2012-01-30 00:45:05 UTC ---
I'm not here to argue semantics.  I use -Wdeclaration-after-statement to avoid
accidentally introducing code that will fail with compilers that do not support
this.  Having an equivalent for the for loop construct would have saved me some
time today.  If all compilers supported C99 fully, there would be no need for
any of this, but sadly this is not the case.


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

* [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements.
  2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
                   ` (3 preceding siblings ...)
  2012-01-30  7:23 ` mans at mansr dot com
@ 2012-01-30  9:28 ` rguenth at gcc dot gnu.org
  2023-05-20  4:19 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-01-30  9:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-30 09:23:45 UTC ---
I agree that a separate warning option should be used here.


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

* [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements.
  2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
                   ` (4 preceding siblings ...)
  2012-01-30  9:28 ` rguenth at gcc dot gnu.org
@ 2023-05-20  4:19 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-20  4:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |87403

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is now warning with -Wc90-c99-compat (since GCC 9). Though it does not
have its own option.


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] 7+ messages in thread

end of thread, other threads:[~2023-05-20  4:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-29 23:14 [Bug c/52050] New: -Wdeclaration-after-statement does not warn on declaration in for loop initialiser mans at mansr dot com
2012-01-29 23:57 ` [Bug c/52050] " steven at gcc dot gnu.org
2012-01-30  0:11 ` mans at mansr dot com
2012-01-30  7:15 ` [Bug c/52050] Want an option to warn about a declaration inside a for/while/if statements pinskia at gcc dot gnu.org
2012-01-30  7:23 ` mans at mansr dot com
2012-01-30  9:28 ` rguenth at gcc dot gnu.org
2023-05-20  4:19 ` 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).