public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101446] New: -Wpedantic causes an error with zero size array
@ 2021-07-14 8:26 ismail at i10z dot com
2021-07-14 9:35 ` [Bug c/101446] " redi at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: ismail at i10z dot com @ 2021-07-14 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
Bug ID: 101446
Summary: -Wpedantic causes an error with zero size array
Product: gcc
Version: 11.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ismail at i10z dot com
Target Milestone: ---
The test-case minimized but originally from glibc:
; cat gbk.c
static const char __gbk_from_ucs4_tab9[][2] =
{
};
; gcc -c gbk.c
; gcc -c -Wpedantic gbk.c
gbk.c:2:1: warning: ISO C forbids empty initializer braces [-Wpedantic]
2 | {
| ^
gbk.c:1:19: error: zero or negative size array ‘__gbk_from_ucs4_tab9’
1 | static const char __gbk_from_ucs4_tab9[][2] =
| ^~~~~~~~~~~~~~~~~~~~
; gcc -v
(base)
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,ada,go,d,jit
--enable-offload-targets=nvptx-none,amdgcn-amdhsa, --without-cuda-driver
--enable-host-shared --enable-checking=release --disable-werror
--with-gxx-include-dir=/usr/include/c++/11 --enable-ssp --disable-libssp
--disable-libvtv --enable-cet=auto --disable-libcc1 --enable-plugin
--with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new
--disable-libstdcxx-pch --enable-libphobos
--enable-version-specific-runtime-libs --with-gcc-major-version-only
--enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function
--program-suffix=-11 --without-system-libunwind --enable-multilib
--with-arch-32=x86-64 --with-tune=generic
--with-build-config=bootstrap-lto-lean --enable-link-mutex
--build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.1 20210625 [revision 62bbb113ae68a7e724255e17143520735bcb9ec9]
(SUSE Linux)
I believe no warning flag should result in an error.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
@ 2021-07-14 9:35 ` redi at gcc dot gnu.org
2021-07-14 9:40 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-14 9:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's been that way since GCC 4.1 at least.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
2021-07-14 9:35 ` [Bug c/101446] " redi at gcc dot gnu.org
@ 2021-07-14 9:40 ` rguenth at gcc dot gnu.org
2021-07-14 9:42 ` ismail at i10z dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-14 9:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
-Wpedantic is the same as -pedantic and that affects correctness of programs.
@item -Wpedantic
@itemx -pedantic
@opindex pedantic
@opindex Wpedantic
@opindex Wno-pedantic
Issue all the warnings demanded by strict ISO C and ISO C++;
reject all programs that use forbidden extensions, and some other
programs that do not follow ISO C and ISO C++. For ISO C, follows the
version of the ISO C standard specified by any @option{-std} option used.
Valid ISO C and ISO C++ programs should compile properly with or without
this option (though a rare few require @option{-ansi} or a
@option{-std} option specifying the required version of ISO C)@. However,
without this option, certain GNU extensions and traditional C and C++
features are supported as well. With this option, they are rejected.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
2021-07-14 9:35 ` [Bug c/101446] " redi at gcc dot gnu.org
2021-07-14 9:40 ` rguenth at gcc dot gnu.org
@ 2021-07-14 9:42 ` ismail at i10z dot com
2021-07-14 9:42 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ismail at i10z dot com @ 2021-07-14 9:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
--- Comment #3 from İsmail Dönmez <ismail at i10z dot com> ---
(In reply to Richard Biener from comment #2)
> -Wpedantic is the same as -pedantic and that affects correctness of programs.
>
> @item -Wpedantic
> @itemx -pedantic
> @opindex pedantic
> @opindex Wpedantic
> @opindex Wno-pedantic
> Issue all the warnings demanded by strict ISO C and ISO C++;
> reject all programs that use forbidden extensions, and some other
> programs that do not follow ISO C and ISO C++. For ISO C, follows the
> version of the ISO C standard specified by any @option{-std} option used.
>
> Valid ISO C and ISO C++ programs should compile properly with or without
> this option (though a rare few require @option{-ansi} or a
> @option{-std} option specifying the required version of ISO C)@. However,
> without this option, certain GNU extensions and traditional C and C++
> features are supported as well. With this option, they are rejected.
Well, not quite so. I enabled -Wpedantic with glibc and have hundreds of
warnings and only the zero-size array one errors out. There is clearly an
inconsistency here.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
` (2 preceding siblings ...)
2021-07-14 9:42 ` ismail at i10z dot com
@ 2021-07-14 9:42 ` rguenth at gcc dot gnu.org
2021-07-14 9:46 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-14 9:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
-Wpedantic was added as fix for PR44774 to make -Werror=pedantic work
(as opposed to -Werror=edantic)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
` (3 preceding siblings ...)
2021-07-14 9:42 ` rguenth at gcc dot gnu.org
@ 2021-07-14 9:46 ` rguenth at gcc dot gnu.org
2021-07-14 9:47 ` ismail at i10z dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-14 9:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-07-14
Status|RESOLVED |NEW
CC| |jsm28 at gcc dot gnu.org
Resolution|INVALID |---
Ever confirmed|0 |1
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, so the complaint is that
> ./cc1 -quiet t.c -pedantic
t.c:1:47: warning: ISO C forbids empty initializer braces [-Wpedantic]
1 | static const char __gbk_from_ucs4_tab9[][2] = {};
| ^
t.c:1:19: error: zero or negative size array '__gbk_from_ucs4_tab9'
1 | static const char __gbk_from_ucs4_tab9[][2] = {};
| ^~~~~~~~~~~~~~~~~~~~
errors and not only -pedantic-errors
> ./cc1 -quiet t.c -pedantic-errors
t.c:1:47: error: ISO C forbids empty initializer braces [-Wpedantic]
1 | static const char __gbk_from_ucs4_tab9[][2] = {};
| ^
t.c:1:19: error: zero or negative size array '__gbk_from_ucs4_tab9'
1 | static const char __gbk_from_ucs4_tab9[][2] = {};
| ^~~~~~~~~~~~~~~~~~~~
-Wpedantic is just an alias for -pedantic - but see the documentation which
explicitely says some constructs are rejected (not only warned on).
-pedantic-errors says
@item -pedantic-errors
@opindex pedantic-errors
Give an error whenever the @dfn{base standard} (see @option{-Wpedantic})
requires a diagnostic, in some cases where there is undefined behavior
at compile-time and in some other cases that do not prevent compilation
of programs that are valid according to the standard. This is not
equivalent to @option{-Werror=pedantic}, since there are errors enabled
by this option and not enabled by the latter and vice versa.
so I still think it works as designed even if the new -Wpedantic alias
suggests that -pedantic is a pure warning option.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
` (4 preceding siblings ...)
2021-07-14 9:46 ` rguenth at gcc dot gnu.org
@ 2021-07-14 9:47 ` ismail at i10z dot com
2021-07-14 10:25 ` ismail at i10z dot com
2021-07-14 15:21 ` joseph at codesourcery dot com
7 siblings, 0 replies; 9+ messages in thread
From: ismail at i10z dot com @ 2021-07-14 9:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
--- Comment #6 from İsmail Dönmez <ismail at i10z dot com> ---
(In reply to Richard Biener from comment #4)
> -Wpedantic was added as fix for PR44774 to make -Werror=pedantic work
> (as opposed to -Werror=edantic)
The problem is that it's inconsistent, here is a list of other -Wpedantic
warnings that do not result in an error:
ISO C does not support the '_Float128' type [-Wpedantic]
ISO C does not support the '_Float32' type [-Wpedantic]
ISO C does not support the '_Float32x' type [-Wpedantic]
ISO C does not support the '_Float64' type [-Wpedantic]
ISO C does not support the '_Float64x' type [-Wpedantic]
ISO C does not support the ‘_Float128’ type [-Wpedantic]
ISO C does not support the ‘_Float32x’ type [-Wpedantic]
ISO C does not support the ‘_Float32’ type [-Wpedantic]
ISO C does not support the ‘_Float64x’ type [-Wpedantic]
ISO C does not support the ‘_Float64’ type [-Wpedantic]
ISO C forbids 'goto *expr;' [-Wpedantic]
ISO C forbids 'return' with expression, in function returning void [-Wpedantic]
ISO C forbids an empty translation unit [-Wpedantic]
ISO C forbids assignment between function pointer and 'void *' [-Wpedantic]
ISO C forbids braced-groups within expressions [-Wpedantic]
ISO C forbids conditional expr with only one void side [-Wpedantic]
ISO C forbids conversion of function pointer to object pointer type
[-Wpedantic]
ISO C forbids conversion of object pointer to function pointer type
[-Wpedantic]
ISO C forbids empty initializer braces [-Wpedantic]
ISO C forbids forward references to 'enum' types [-Wpedantic]
ISO C forbids initialization between function pointer and 'void *' [-Wpedantic]
ISO C forbids label declarations [-Wpedantic]
ISO C forbids omitting the middle term of a '?:' expression [-Wpedantic]
ISO C forbids passing argument 1 of '_dl_addr' between function pointer and
'void *' [-Wpedantic]
ISO C forbids return between function pointer and 'void *' [-Wpedantic]
ISO C forbids specifying range of elements to initialize [-Wpedantic]
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
` (5 preceding siblings ...)
2021-07-14 9:47 ` ismail at i10z dot com
@ 2021-07-14 10:25 ` ismail at i10z dot com
2021-07-14 15:21 ` joseph at codesourcery dot com
7 siblings, 0 replies; 9+ messages in thread
From: ismail at i10z dot com @ 2021-07-14 10:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
--- Comment #7 from İsmail Dönmez <ismail at i10z dot com> ---
Well, it's even more confusing, grepping through glibc build log:
../include/stdlib.h:297:8: warning: ISO C forbids zero-size array 'msg'
[-Wpedantic]
297 | char msg[0];
| ^~~
../inet/netinet/ip6.h:92:21: warning: ISO C forbids zero-size array
'ip6r0_addr' [-Wpedantic]
92 | struct in6_addr ip6r0_addr[0];
| ^~~~~~~~~~
So even the zero-size array warning behaves differently.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/101446] -Wpedantic causes an error with zero size array
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
` (6 preceding siblings ...)
2021-07-14 10:25 ` ismail at i10z dot com
@ 2021-07-14 15:21 ` joseph at codesourcery dot com
7 siblings, 0 replies; 9+ messages in thread
From: joseph at codesourcery dot com @ 2021-07-14 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101446
--- Comment #8 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
I think this is a bug. Negative-size arrays are an unconditional error.
Zero-size arrays should be a pedwarn-if-pedantic, regardless of whether
the 0 is explicit or deduced from an initializer.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-07-14 15:21 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 8:26 [Bug c/101446] New: -Wpedantic causes an error with zero size array ismail at i10z dot com
2021-07-14 9:35 ` [Bug c/101446] " redi at gcc dot gnu.org
2021-07-14 9:40 ` rguenth at gcc dot gnu.org
2021-07-14 9:42 ` ismail at i10z dot com
2021-07-14 9:42 ` rguenth at gcc dot gnu.org
2021-07-14 9:46 ` rguenth at gcc dot gnu.org
2021-07-14 9:47 ` ismail at i10z dot com
2021-07-14 10:25 ` ismail at i10z dot com
2021-07-14 15:21 ` joseph at codesourcery dot com
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).