public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/38019] New: Cannot use nested designated initializer with unnamed inner aggregate @ 2008-11-05 9:27 josh at freedesktop dot org 2008-11-05 9:37 ` [Bug c/38019] " rguenth at gcc dot gnu dot org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: josh at freedesktop dot org @ 2008-11-05 9:27 UTC (permalink / raw) To: gcc-bugs [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2279 bytes --] I have an aggregate with this definition: typedef union vec3 { struct { double x, y, z; }; double component[3]; } vec3; Given this definition, I tried to write the following: static inline vec3 vec_add(vec3 a, vec3 b) { return (vec3) { .x = a.x + b.x, .y = a.y + b.y, .z = a.z + b.z, }; } GCC complained about this: vec.h: In function vec_add: vec.h:15: error: missing braces around initializer vec.h:15: error: (near initialization for (anonymous).<anonymous>) If I had given the nameless inner struct a name, such as "foo", I could have written: static inline vec3 vec_add(vec3 a, vec3 b) { return (vec3) { .foo.x = a.foo.x + b.foo.x, .foo.y = a.foo.y + b.foo.y, .foo.z = a.foo.z + b.foo.z, }; } So since the inner struct does not have a name, it seems reasonable to allow a designated initializer to omit the name. GCC has no problem unambiguously resolving the field reference a.x, so it seems like GCC should unambiguously resolve the designated initializer .x = expression. In case it helps: $ gcc -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-cld --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.3.2 (Debian 4.3.2-1) -- Summary: Cannot use nested designated initializer with unnamed inner aggregate Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: josh at freedesktop dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38019 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/38019] Cannot use nested designated initializer with unnamed inner aggregate 2008-11-05 9:27 [Bug c/38019] New: Cannot use nested designated initializer with unnamed inner aggregate josh at freedesktop dot org @ 2008-11-05 9:37 ` rguenth at gcc dot gnu dot org 2008-11-05 13:49 ` joseph at codesourcery dot com 2008-11-05 17:20 ` josh at freedesktop dot org 2 siblings, 0 replies; 4+ messages in thread From: rguenth at gcc dot gnu dot org @ 2008-11-05 9:37 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from rguenth at gcc dot gnu dot org 2008-11-05 09:36 ------- I get t.c: In function 'vec_add': t.c:10: error: unknown field 'x' specified in initializer t.c:11: error: unknown field 'y' specified in initializer t.c:11: warning: excess elements in union initializer t.c:11: warning: (near initialization for '(anonymous)') t.c:12: error: unknown field 'z' specified in initializer t.c:12: warning: excess elements in union initializer t.c:12: warning: (near initialization for '(anonymous)') instead. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38019 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/38019] Cannot use nested designated initializer with unnamed inner aggregate 2008-11-05 9:27 [Bug c/38019] New: Cannot use nested designated initializer with unnamed inner aggregate josh at freedesktop dot org 2008-11-05 9:37 ` [Bug c/38019] " rguenth at gcc dot gnu dot org @ 2008-11-05 13:49 ` joseph at codesourcery dot com 2008-11-05 17:20 ` josh at freedesktop dot org 2 siblings, 0 replies; 4+ messages in thread From: joseph at codesourcery dot com @ 2008-11-05 13:49 UTC (permalink / raw) To: gcc-bugs ------- Comment #2 from joseph at codesourcery dot com 2008-11-05 13:47 ------- Subject: Re: Cannot use nested designated initializer with unnamed inner aggregate On Wed, 5 Nov 2008, rguenth at gcc dot gnu dot org wrote: > I get > > t.c: In function 'vec_add': > t.c:10: error: unknown field 'x' specified in initializer > t.c:11: error: unknown field 'y' specified in initializer > t.c:11: warning: excess elements in union initializer > t.c:11: warning: (near initialization for '(anonymous)') > t.c:12: error: unknown field 'z' specified in initializer > t.c:12: warning: excess elements in union initializer > t.c:12: warning: (near initialization for '(anonymous)') > > instead. That matches bug 10676. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38019 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/38019] Cannot use nested designated initializer with unnamed inner aggregate 2008-11-05 9:27 [Bug c/38019] New: Cannot use nested designated initializer with unnamed inner aggregate josh at freedesktop dot org 2008-11-05 9:37 ` [Bug c/38019] " rguenth at gcc dot gnu dot org 2008-11-05 13:49 ` joseph at codesourcery dot com @ 2008-11-05 17:20 ` josh at freedesktop dot org 2 siblings, 0 replies; 4+ messages in thread From: josh at freedesktop dot org @ 2008-11-05 17:20 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from josh at freedesktop dot org 2008-11-05 17:19 ------- Sigh. Yes, I get the same set of errors. I seem to have managed to copy and paste the wrong set of messages. This does indeed look like a duplicate of bug 10676. Marking as such. *** This bug has been marked as a duplicate of 10676 *** -- josh at freedesktop dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |DUPLICATE http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38019 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-11-05 17:20 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-11-05 9:27 [Bug c/38019] New: Cannot use nested designated initializer with unnamed inner aggregate josh at freedesktop dot org 2008-11-05 9:37 ` [Bug c/38019] " rguenth at gcc dot gnu dot org 2008-11-05 13:49 ` joseph at codesourcery dot com 2008-11-05 17:20 ` josh at freedesktop dot 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).