public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54162] New: Does not accept static global anonymous unions or structs
@ 2012-08-02 23:04 josh at joshtriplett dot org
  2012-08-02 23:23 ` [Bug c/54162] " joseph at codesourcery dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: josh at joshtriplett dot org @ 2012-08-02 23:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54162

             Bug #: 54162
           Summary: Does not accept static global anonymous unions or
                    structs
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: josh@joshtriplett.org


C1X, and numerous other compilers, support static anonymous unions or structs
at file scope.  For example, the following code should work with a C1X
compiler:

static union {
    unsigned x;
    unsigned y;
};

int main(void)
{
    x = 5;
    return y;
}

However, GCC says:

test.c:4:1: warning: unnamed struct/union that defines no instances [enabled by
default]
test.c: In function ‘main’:
test.c:8:5: error: ‘x’ undeclared (first use in this function)
test.c:8:5: note: each undeclared identifier is reported only once for each
function it appears in
test.c:9:12: error: ‘y’ undeclared (first use in this function)


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

* [Bug c/54162] Does not accept static global anonymous unions or structs
  2012-08-02 23:04 [Bug c/54162] New: Does not accept static global anonymous unions or structs josh at joshtriplett dot org
@ 2012-08-02 23:23 ` joseph at codesourcery dot com
  2012-08-03  8:07 ` rguenth at gcc dot gnu.org
  2012-08-20 14:50 ` [Bug c/54162] Please accept static global anonymous unions or structs as an extension josh at joshtriplett dot org
  2 siblings, 0 replies; 4+ messages in thread
From: joseph at codesourcery dot com @ 2012-08-02 23:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54162

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-08-02 23:23:19 UTC ---
On Thu, 2 Aug 2012, josh at joshtriplett dot org wrote:

> C1X, and numerous other compilers, support static anonymous unions or structs
> at file scope.  For example, the following code should work with a C1X
> compiler:

No it shouldn't.  Anonymous structures and unions are *members* of a 
containing structure or union, not declarations outside such a context; 
see C11 6.7.2.1 paragraph 13.  The constraint in 6.7 paragraph 2 applies: 
"A declaration other than a static_assert declaration shall declare at 
least a declarator (other than the parameters of a function or the members 
of a structure or union), a tag, or the members of an enumeration.".  Your 
union declares none of those.


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

* [Bug c/54162] Does not accept static global anonymous unions or structs
  2012-08-02 23:04 [Bug c/54162] New: Does not accept static global anonymous unions or structs josh at joshtriplett dot org
  2012-08-02 23:23 ` [Bug c/54162] " joseph at codesourcery dot com
@ 2012-08-03  8:07 ` rguenth at gcc dot gnu.org
  2012-08-20 14:50 ` [Bug c/54162] Please accept static global anonymous unions or structs as an extension josh at joshtriplett dot org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-08-03  8:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54162

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-08-03 08:07:12 UTC ---
Thus invalid.


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

* [Bug c/54162] Please accept static global anonymous unions or structs as an extension
  2012-08-02 23:04 [Bug c/54162] New: Does not accept static global anonymous unions or structs josh at joshtriplett dot org
  2012-08-02 23:23 ` [Bug c/54162] " joseph at codesourcery dot com
  2012-08-03  8:07 ` rguenth at gcc dot gnu.org
@ 2012-08-20 14:50 ` josh at joshtriplett dot org
  2 siblings, 0 replies; 4+ messages in thread
From: josh at joshtriplett dot org @ 2012-08-20 14:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54162

Josh Triplett <josh at joshtriplett dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |
            Summary|Does not accept static      |Please accept static global
                   |global anonymous unions or  |anonymous unions or structs
                   |structs                     |as an extension

--- Comment #3 from Josh Triplett <josh at joshtriplett dot org> 2012-08-20 14:50:35 UTC ---
How odd.  Quite a number of sources seem to suggest that C11 allows this.  But
in any case, several other compilers *do* allow this syntax; thus, reopening
this and turning it into a request for an extension.


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

end of thread, other threads:[~2012-08-20 14:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-02 23:04 [Bug c/54162] New: Does not accept static global anonymous unions or structs josh at joshtriplett dot org
2012-08-02 23:23 ` [Bug c/54162] " joseph at codesourcery dot com
2012-08-03  8:07 ` rguenth at gcc dot gnu.org
2012-08-20 14:50 ` [Bug c/54162] Please accept static global anonymous unions or structs as an extension josh at joshtriplett 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).