public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc 13.2 is missing warnings?
@ 2023-10-19 11:39 Eric Sokolowsky
  2023-10-19 11:49 ` Martin Uecker
  2023-10-19 11:54 ` Richard Earnshaw
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Sokolowsky @ 2023-10-19 11:39 UTC (permalink / raw)
  To: gcc

I am using gcc 13.2 on Fedora 38. Consider the following program.

#include <stdio.h>
int main(int argc, char **argv)
{
    printf("Enter a number: ");
    int num = 0;
    scanf("%d", &num);

    switch (num)
    {
    case 1:
        int a = num + 3;
        printf("The new number is %d.\n", a);
        break;
    case 2:
        int b = num - 4;
        printf("The new number is %d.\n", b);
        break;
    default:
        int c = num * 3;
        printf("The new number is %d.\n", c);
        break;
    }
}

I would expect that gcc would complain about the declaration of
variables (a, b, and c) within the case statements. When I run "gcc
-Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get
warnings and errors as expected. I do get warnings when using MinGW on
Windows (gcc version 6.3 specifically). Did something change in 13.2?

Eric

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

* Re: gcc 13.2 is missing warnings?
  2023-10-19 11:39 gcc 13.2 is missing warnings? Eric Sokolowsky
@ 2023-10-19 11:49 ` Martin Uecker
  2023-10-19 11:51   ` Martin Uecker
  2023-10-19 13:41   ` Eric Sokolowsky
  2023-10-19 11:54 ` Richard Earnshaw
  1 sibling, 2 replies; 6+ messages in thread
From: Martin Uecker @ 2023-10-19 11:49 UTC (permalink / raw)
  To: esok127, gcc




GCC supports this as an extension.

Mixing declarations and code is allowed in C99 and C23 
will also allow placing labels before declarations and at
the end of a compound statement. GCC supports all this
also in earlier language modes.

See:
https://gcc.gnu.org/onlinedocs/gcc/Mixed-Labels-and-Declarations.html

You will get the warnings with -pedantic.

Martin

Am Donnerstag, dem 19.10.2023 um 07:39 -0400 schrieb Eric Sokolowsky via Gcc:
> I am using gcc 13.2 on Fedora 38. Consider the following program.
> 
> #include <stdio.h>
> int main(int argc, char **argv)
> {
>     printf("Enter a number: ");
>     int num = 0;
>     scanf("%d", &num);
> 
>     switch (num)
>     {
>     case 1:
>         int a = num + 3;
>         printf("The new number is %d.\n", a);
>         break;
>     case 2:
>         int b = num - 4;
>         printf("The new number is %d.\n", b);
>         break;
>     default:
>         int c = num * 3;
>         printf("The new number is %d.\n", c);
>         break;
>     }
> }
> 
> I would expect that gcc would complain about the declaration of
> variables (a, b, and c) within the case statements. When I run "gcc
> -Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get
> warnings and errors as expected. I do get warnings when using MinGW on
> Windows (gcc version 6.3 specifically). Did something change in 13.2?
> 
> Eric


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

* Re: gcc 13.2 is missing warnings?
  2023-10-19 11:49 ` Martin Uecker
@ 2023-10-19 11:51   ` Martin Uecker
  2023-10-19 23:11     ` Eric Gallager
  2023-10-19 13:41   ` Eric Sokolowsky
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Uecker @ 2023-10-19 11:51 UTC (permalink / raw)
  To: esok127, gcc



Note that the C++ warning is for jumping over a declaration,
which is generally allowed in C but not in C++.

Martin

Am Donnerstag, dem 19.10.2023 um 13:49 +0200 schrieb Martin Uecker:
> 
> 
> GCC supports this as an extension.
> 
> Mixing declarations and code is allowed in C99 and C23 
> will also allow placing labels before declarations and at
> the end of a compound statement. GCC supports all this
> also in earlier language modes.
> 
> See:
> https://gcc.gnu.org/onlinedocs/gcc/Mixed-Labels-and-Declarations.html
> 
> You will get the warnings with -pedantic.
> 
> Martin
> 
> Am Donnerstag, dem 19.10.2023 um 07:39 -0400 schrieb Eric Sokolowsky via Gcc:
> > I am using gcc 13.2 on Fedora 38. Consider the following program.
> > 
> > #include <stdio.h>
> > int main(int argc, char **argv)
> > {
> >     printf("Enter a number: ");
> >     int num = 0;
> >     scanf("%d", &num);
> > 
> >     switch (num)
> >     {
> >     case 1:
> >         int a = num + 3;
> >         printf("The new number is %d.\n", a);
> >         break;
> >     case 2:
> >         int b = num - 4;
> >         printf("The new number is %d.\n", b);
> >         break;
> >     default:
> >         int c = num * 3;
> >         printf("The new number is %d.\n", c);
> >         break;
> >     }
> > }
> > 
> > I would expect that gcc would complain about the declaration of
> > variables (a, b, and c) within the case statements. When I run "gcc
> > -Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get
> > warnings and errors as expected. I do get warnings when using MinGW on
> > Windows (gcc version 6.3 specifically). Did something change in 13.2?
> > 
> > Eric
> 


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

* Re: gcc 13.2 is missing warnings?
  2023-10-19 11:39 gcc 13.2 is missing warnings? Eric Sokolowsky
  2023-10-19 11:49 ` Martin Uecker
@ 2023-10-19 11:54 ` Richard Earnshaw
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Earnshaw @ 2023-10-19 11:54 UTC (permalink / raw)
  To: esok127, gcc



On 19/10/2023 12:39, Eric Sokolowsky via Gcc wrote:
> I am using gcc 13.2 on Fedora 38. Consider the following program.
> 
> #include <stdio.h>
> int main(int argc, char **argv)
> {
>      printf("Enter a number: ");
>      int num = 0;
>      scanf("%d", &num);
> 
>      switch (num)
>      {
>      case 1:
>          int a = num + 3;
>          printf("The new number is %d.\n", a);
>          break;
>      case 2:
>          int b = num - 4;
>          printf("The new number is %d.\n", b);
>          break;
>      default:
>          int c = num * 3;
>          printf("The new number is %d.\n", c);
>          break;
>      }
> }
> 
> I would expect that gcc would complain about the declaration of
> variables (a, b, and c) within the case statements. When I run "gcc
> -Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get
> warnings and errors as expected. I do get warnings when using MinGW on
> Windows (gcc version 6.3 specifically). Did something change in 13.2?
> 
> Eric

The analysis needed to generate useful warnings is often not run unless 
the optimizers are enabled.  Try adding -O, or even higher.  -O0 is 
generally only recommended for syntax checking.

R.

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

* Re: gcc 13.2 is missing warnings?
  2023-10-19 11:49 ` Martin Uecker
  2023-10-19 11:51   ` Martin Uecker
@ 2023-10-19 13:41   ` Eric Sokolowsky
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Sokolowsky @ 2023-10-19 13:41 UTC (permalink / raw)
  To: gcc

Thank you for your message. Indeed, the -pedantic flag gives me the
warning I expect. -O (as suggested in another response) does not.

Eric

On Thu, Oct 19, 2023 at 7:49 AM Martin Uecker <muecker@gwdg.de> wrote:
>
>
>
>
> GCC supports this as an extension.
>
> Mixing declarations and code is allowed in C99 and C23
> will also allow placing labels before declarations and at
> the end of a compound statement. GCC supports all this
> also in earlier language modes.
>
> See:
> https://gcc.gnu.org/onlinedocs/gcc/Mixed-Labels-and-Declarations.html
>
> You will get the warnings with -pedantic.
>
> Martin
>
> Am Donnerstag, dem 19.10.2023 um 07:39 -0400 schrieb Eric Sokolowsky via Gcc:
> > I am using gcc 13.2 on Fedora 38. Consider the following program.
> >
> > #include <stdio.h>
> > int main(int argc, char **argv)
> > {
> >     printf("Enter a number: ");
> >     int num = 0;
> >     scanf("%d", &num);
> >
> >     switch (num)
> >     {
> >     case 1:
> >         int a = num + 3;
> >         printf("The new number is %d.\n", a);
> >         break;
> >     case 2:
> >         int b = num - 4;
> >         printf("The new number is %d.\n", b);
> >         break;
> >     default:
> >         int c = num * 3;
> >         printf("The new number is %d.\n", c);
> >         break;
> >     }
> > }
> >
> > I would expect that gcc would complain about the declaration of
> > variables (a, b, and c) within the case statements. When I run "gcc
> > -Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get
> > warnings and errors as expected. I do get warnings when using MinGW on
> > Windows (gcc version 6.3 specifically). Did something change in 13.2?
> >
> > Eric
>

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

* Re: gcc 13.2 is missing warnings?
  2023-10-19 11:51   ` Martin Uecker
@ 2023-10-19 23:11     ` Eric Gallager
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Gallager @ 2023-10-19 23:11 UTC (permalink / raw)
  To: Martin Uecker; +Cc: esok127, gcc

On Thu, Oct 19, 2023 at 7:52 AM Martin Uecker <muecker@gwdg.de> wrote:
>
>
>
> Note that the C++ warning is for jumping over a declaration,
> which is generally allowed in C but not in C++.
>
> Martin

(Also note that in C, there's -Wjump-misses-init for this, which is
enabled by -Wc++-compat, which isn't enabled by anything else, and has
to be requested manually)

>
> Am Donnerstag, dem 19.10.2023 um 13:49 +0200 schrieb Martin Uecker:
> >
> >
> > GCC supports this as an extension.
> >
> > Mixing declarations and code is allowed in C99 and C23
> > will also allow placing labels before declarations and at
> > the end of a compound statement. GCC supports all this
> > also in earlier language modes.
> >
> > See:
> > https://gcc.gnu.org/onlinedocs/gcc/Mixed-Labels-and-Declarations.html
> >
> > You will get the warnings with -pedantic.
> >
> > Martin
> >
> > Am Donnerstag, dem 19.10.2023 um 07:39 -0400 schrieb Eric Sokolowsky via Gcc:
> > > I am using gcc 13.2 on Fedora 38. Consider the following program.
> > >
> > > #include <stdio.h>
> > > int main(int argc, char **argv)
> > > {
> > >     printf("Enter a number: ");
> > >     int num = 0;
> > >     scanf("%d", &num);
> > >
> > >     switch (num)
> > >     {
> > >     case 1:
> > >         int a = num + 3;
> > >         printf("The new number is %d.\n", a);
> > >         break;
> > >     case 2:
> > >         int b = num - 4;
> > >         printf("The new number is %d.\n", b);
> > >         break;
> > >     default:
> > >         int c = num * 3;
> > >         printf("The new number is %d.\n", c);
> > >         break;
> > >     }
> > > }
> > >
> > > I would expect that gcc would complain about the declaration of
> > > variables (a, b, and c) within the case statements. When I run "gcc
> > > -Wall t.c" I get no warnings. When I run "g++ -Wall t.c" I get
> > > warnings and errors as expected. I do get warnings when using MinGW on
> > > Windows (gcc version 6.3 specifically). Did something change in 13.2?
> > >
> > > Eric
> >
>

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

end of thread, other threads:[~2023-10-19 23:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 11:39 gcc 13.2 is missing warnings? Eric Sokolowsky
2023-10-19 11:49 ` Martin Uecker
2023-10-19 11:51   ` Martin Uecker
2023-10-19 23:11     ` Eric Gallager
2023-10-19 13:41   ` Eric Sokolowsky
2023-10-19 11:54 ` Richard Earnshaw

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).