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

            Bug ID: 117241
           Summary: Various pedwarns in c-decl.cc are behind
                    !in_system_header_at
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arsen at gcc dot gnu.org
  Target Milestone: ---

When trying to check a libc for >C90 features in headers by running compiling
with:

  -std=c89 -pedantic-errors -Wsystem-headers -x c /dev/null -isystem
sysroot/usr/include -include <header>.h

... it was noted that flexible array members weren't being reported.  Take, for
instance, the following TU:

  # 1 "/tmp/hg/test.h" 3 4
  struct S { char x; char name[]; };

... this should emit a warning (and indeed swapping '3 4' with '1' makes the
warning appear), but does not due to this check:

                if (flexible_array_member
                    && !in_system_header_at (input_location))
                  pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
                               "support flexible array members");

in c-decl.cc:grokdeclarator.  When removing the in_system_header_at check,
-Wsystem-headers seemed to be understood correctly:

  ~/gcc/_b_coro-fixes/gcc 1 $ git -C ~/gcc/coro-fixes --no-pager diff
  diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
  index aa7f69d1b7bc..f7387b9b7711 100644
  --- a/gcc/c/c-decl.cc
  +++ b/gcc/c/c-decl.cc
  @@ -7490,7 +7490,7 @@ grokdeclarator (const struct c_declarator *declarator,
                     flexible_array_member = (t->kind == cdk_id);
                   }
                  if (flexible_array_member
  -                  && !in_system_header_at (input_location))
  +                  && !0)//in_system_header_at (input_location))
                   pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not "
                                "support flexible array members");

  ~/gcc/_b_coro-fixes/gcc$ ./cc1 -quiet -v - -quiet -dumpbase - -mtune=generic
-march=x86-64 -pedantic-errors -std=c90 -version -fpreprocessed -o /dev/null
-fcf-protection<<-EOF
  # 1 "/tmp/hg/test.h" 3
  struct S { char x; char name[]; };
  EOF
  GNU C89 (GCC) version 15.0.0 20240927 (experimental) (x86_64-pc-linux-gnu)
        compiled by GNU C version 14.2.1 20240921, GMP version 6.3.0, MPFR
version 4.2.1, MPC version 1.3.1, isl version isl-0.27-GMP

  GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
  ignoring nonexistent directory "/usr/local/include"
  ignoring nonexistent directory
"/home/arsen/gcc/_b_coro-fixes/_pfx/lib/gcc/x86_64-pc-linux-gnu/15.0.0/../../../../x86_64-pc-linux-gnu/include"
  #include "..." search starts here:
  #include <...> search starts here:
  
/home/arsen/gcc/_b_coro-fixes/_pfx/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include
   /home/arsen/gcc/_b_coro-fixes/_pfx/include
  
/home/arsen/gcc/_b_coro-fixes/_pfx/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include-fixed
   /usr/include
  End of search list.
  Compiler executable checksum: 175a97d69d759221b576ba224ecb364c
  ~/gcc/_b_coro-fixes/gcc$ ./cc1 -Wsystem-headers -quiet -v - -quiet -dumpbase
- -mtune=generic -march=x86-64 -pedantic-errors -std=c90 -ve
  rsion -fpreprocessed -o /dev/null -fcf-protection<<-EOF
  # 1 "/tmp/hg/test.h" 3
  struct S { char x; char name[]; };
  EOF
  GNU C89 (GCC) version 15.0.0 20240927 (experimental) (x86_64-pc-linux-gnu)
        compiled by GNU C version 14.2.1 20240921, GMP version 6.3.0, MPFR
version 4.2.1, MPC version 1.3.1, isl version isl-0.27-GMP

  GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
  ignoring nonexistent directory "/usr/local/include"
  ignoring nonexistent directory
"/home/arsen/gcc/_b_coro-fixes/_pfx/lib/gcc/x86_64-pc-linux-gnu/15.0.0/../../../../x86_64-pc-linux-gnu/include"
  #include "..." search starts here:
  #include <...> search starts here:
  
/home/arsen/gcc/_b_coro-fixes/_pfx/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include
   /home/arsen/gcc/_b_coro-fixes/_pfx/include
  
/home/arsen/gcc/_b_coro-fixes/_pfx/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include-fixed
   /usr/include
  End of search list.
  Compiler executable checksum: 175a97d69d759221b576ba224ecb364c
  /tmp/hg/test.h:1:25: error: ISO C90 does not support flexible array members
[-Wpedantic]
      1 | struct S { char x; char name[]; };
        |                         ^~~~
  ~/gcc/_b_coro-fixes/gcc 1 $ 

... so, perhaps the checks are an artifact of a bygone time before
-Wsystem-headers :-)

Reply via email to