https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64918
Bug ID: 64918
Summary: invalid (?) warning when initializing structure
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: oystein at gnubg dot org
Created attachment 34651
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34651&action=edit
Code that trigger the invalid warning.
Hi!
I'm initializing a complex structure with designated initialisers and
overriding an array element (intentionally), and I then get the error message:
sideffects.c:26:13: warning: initialized field with side-effects overwritten
[3] = { .func = thefunction, .args = &((char*[]){"foo4", "bar4",
"baz4"})},
^
sideffects.c:26:13: warning: (near initialization for 'myconfig.config[3]')
However I do believe my code is correct. It complains about initializing with
side-effects, but I think my code is legal c99. (Please tell me otherwise.)
I compile the attached code with:
gcc -std=gnu99 -Wall -Wextra -Wno-override-init sideeffects.c -o sideeffects
I have tried several different versions of GCC, and here is a short summary:
GCC 4.9.2 (Arch Linux x86_64) -> Warning generated.
GCC 4.9.2 (Mingw32-w64 x86_64) -> Warning generated.
GCC 4.8.0 (Linux x86_64) -> Warning generated.
GCC 4.4.7 (Red Hat 4.4.7-4) -> No warning.
GCC 4.1.2 (Red Hat 4.1.2-52) -> No warning.
clang 3.5.1 (Arch Linux) -> No warning.
Best regards,
-Øystein
Full info on compilers used (Those that generates warning):
[oystein@jupiter ~]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-4.9-20141224/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-cloog-backend=isl --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu --disable-multilib
--disable-werror --enable-checking=release
Thread model: posix
gcc version 4.9.2 20141224 (prerelease) (GCC)
[14:29:03,90 c:\APPL]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/Program\
Files/mingw-w64/x86_64-4.9.2-posix-seh-rt_v3-rev1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.9.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.9.2/configure --host=x86_64-w64-mingw32
--build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64
--with-sysroot=/c/mingw492/x86_64-492-posix-seh-rt_v3-rev1/mingw64
--with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-shared
--enable-static --disable-multilib
--enable-languages=ada,c,c++,fortran,objc,obj-c++,lto
--enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp
--enable-libatomic --enable-lto --enable-graphite --enable-checking=release
--enable-fully-dynamic-string --enable-version-specific-runtime-libs
--disable-isl-version-check --disable-cloog-version-check
--disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap
--disable-rpath --disable-win32-registry --disable-nls --disable-werror
--disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona
--with-tune=core2 --with-libiconv --with-system-zlib
--with-gmp=/c/mingw492/prerequisites/x86_64-w64-mingw32-static
--with-mpfr=/c/mingw492/prerequisites/x86_64-w64-mingw32-static
--with-mpc=/c/mingw492/prerequisites/x86_64-w64-mingw32-static
--with-isl=/c/mingw492/prerequisites/x86_64-w64-mingw32-static
--with-cloog=/c/mingw492/prerequisites/x86_64-w64-mingw32-static
--enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh-rev1, Built by
MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64
CFLAGS='-O2 -pipe
-I/c/mingw492/x86_64-492-posix-seh-rt_v3-rev1/mingw64/opt/include
-I/c/mingw492/prerequisites/x86_64-zlib-static/include
-I/c/mingw492/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2
-pipe -I/c/mingw492/x86_64-492-posix-seh-rt_v3-rev1/mingw64/opt/include
-I/c/mingw492/prerequisites/x86_64-zlib-static/include
-I/c/mingw492/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=
LDFLAGS='-pipe -L/c/mingw492/x86_64-492-posix-seh-rt_v3-rev1/mingw64/opt/lib
-L/c/mingw492/prerequisites/x86_64-zlib-static/lib
-L/c/mingw492/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 4.9.2 (x86_64-posix-seh-rev1, Built by MinGW-W64 project)
[ojohans@st-linapp30 ~/tmp]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/private/ojohans/personal/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk-source/gcc/configure
--enable-languages=c,c++,fortran --enable-checking=release --disable-bootstrap
--disable-libmudflap --disable-libstdcxx-pch --enable-libgomp --enable-lto
--enable-gold --with-plugin-ld=/usr/bin/gold
--with-cloog-include=/usr/include-cloog --with-cloog-lib=/usr/lib64
--prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 4.8.0 20121206 (experimental) [trunk revision 194238] (GCC)