public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15049] New: global variables with anonymous types are legal
@ 2004-04-21 18:08 austern at apple dot com
  2004-04-21 18:13 ` [Bug c++/15049] [3.5 Regression] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: austern at apple dot com @ 2004-04-21 18:08 UTC (permalink / raw)
  To: gcc-bugs

The compiler recently changed to forbid the following construct, where 'x' is a global variable:
  enum { a = 77 } x;
(Or more specifically, the compiler now issues a pedwarn for this construct.  But since pedwarns are 
errors by default, it's fair to say that the compiler now forbids it.)

The comments in the code justify this by pointing to clause 3.5, paragraph 8: "A name with no linkage 
(notably, the name of a class or enumeration declared in a local scope) shall not be used to declare an 
entity with linkage".  

At the very least, this comment is wrong and needs to be clarified.  Yes, a global variable has linkage.  
But we are not declaring 'x' with "a name with no linkage".  x's type has no name, so it can't very well 
have "a name with no linkage".

I've gone through the C++ standards committee's Core Working Group issues list looking for 
clarification.  I've found a number of issues dealing with this.  The most directly relevant are:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#132 (in NAD status)
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#389 (in review status)

Issue 132 was a request that the standard be changed to forbid declaring global variables with 
anonymous types.  The committee refused to do that, and the rationale was specifically that the 
standard currently allows it and that using anonymous enums to declare variable is a common C idiom 
that the committee did not want to break.

Issue 389 is a wholesale clarification of linkage rules as they apply to anonymous types.  It is in "review" 
status, meaning that the core working group is leaning toward this solution and is looking at proposed 
precise wording.  If the wording in issue 389 is accepted, then "enum {a} x" will be forbidden.

So the current status, I think, is pretty clear: in the current C++ standard (C++03), this construct is 
legal.  It will probably be made illegal in a future version of the standard.  ("C++0x")

This means that the compiler should not reject this construct.  This is a rejects-legal.  (And I note that 
this breaks some important programs, like one of the SPEC2004 programs and the Mac version of QT.)

We should probably issue a warning for this construct, since it's likely to be made illegal someday, but 
we shouldn't issue an error.

-- 
           Summary: global variables with anonymous types are legal
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: austern at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: all
  GCC host triplet: all
GCC target triplet: all


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


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

* [Bug c++/15049] [3.5 Regression] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
@ 2004-04-21 18:13 ` pinskia at gcc dot gnu dot org
  2004-04-30  2:13 ` [Bug c++/15049] [3.5 Regression] [DR 278/132/216/338/389/319] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-21 18:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-21 17:41 -------
Confirmed, assigning it to who broke it.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |geoffk at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|                            |1
           Keywords|                            |rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2004-04-21 17:41:10
               date|                            |
            Summary|global variables with       |[3.5 Regression] global
                   |anonymous types are legal   |variables with anonymous
                   |                            |types are legal
   Target Milestone|---                         |3.5.0


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


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

* [Bug c++/15049] [3.5 Regression] [DR 278/132/216/338/389/319] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
  2004-04-21 18:13 ` [Bug c++/15049] [3.5 Regression] " pinskia at gcc dot gnu dot org
@ 2004-04-30  2:13 ` pinskia at gcc dot gnu dot org
  2004-07-22  4:04 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-30  2:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-30 01:38 -------
There is one more issue related DR 278, 338 and 216 and more.

Suspending untill all of these are resolved.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |SUSPENDED
            Summary|[3.5 Regression] global     |[3.5 Regression] [DR
                   |variables with anonymous    |278/132/216/338/389/319]
                   |types are legal             |global variables with
                   |                            |anonymous types are legal


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


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

* [Bug c++/15049] [3.5 Regression] [DR 278/132/216/338/389/319] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
  2004-04-21 18:13 ` [Bug c++/15049] [3.5 Regression] " pinskia at gcc dot gnu dot org
  2004-04-30  2:13 ` [Bug c++/15049] [3.5 Regression] [DR 278/132/216/338/389/319] " pinskia at gcc dot gnu dot org
@ 2004-07-22  4:04 ` pinskia at gcc dot gnu dot org
  2004-07-22 21:15 ` austern at apple dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-22  4:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-22 04:04 -------
: Search converges between 2004-03-01-trunk (#446) and 2004-04-01-trunk (#447).

-- 


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


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

* [Bug c++/15049] [3.5 Regression] [DR 278/132/216/338/389/319] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
                   ` (2 preceding siblings ...)
  2004-07-22  4:04 ` pinskia at gcc dot gnu dot org
@ 2004-07-22 21:15 ` austern at apple dot com
  2004-09-15 21:22 ` [Bug c++/15049] [4.0 " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: austern at apple dot com @ 2004-07-22 21:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From austern at apple dot com  2004-07-22 21:15 -------
There's no mystery about the cause of this behavior.  It's in cp/decl.c:
	  if (TYPE_ANONYMOUS_P (t))
	    {
	      if (DECL_EXTERN_C_P (decl))
		/* Allow this; it's pretty common in C.  */;
	      else
		{
		  pedwarn ("non-local variable `%#D' uses anonymous type",
			   decl);
		  if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
		    cp_pedwarn_at ("\
`%#D' does not refer to the unqualified type, so it is not used for linkage",
				   TYPE_NAME (t));
		}
	    }
	  else
	    pedwarn ("non-local variable `%#D' uses local type `%T'",
			decl, t);
cvs annotate shows that this is a change the Geoff made on 04-Mar-04.

The only question is what to do about this change.  Having read the relevant parts of C++03 standard 
and looked at all relevant CWG issues, I believe that 
  struct { int x; } my_global;
is dubious but legal C++.  ("Dubious" becuase I think it's likely to become illegal in some future 
standard.)

So I believe the right solution is to change that first pedwarn to a warning.

-- 


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


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

* [Bug c++/15049] [4.0 Regression] [DR 278/132/216/338/389/319] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
                   ` (3 preceding siblings ...)
  2004-07-22 21:15 ` austern at apple dot com
@ 2004-09-15 21:22 ` pinskia at gcc dot gnu dot org
  2004-09-21 17:24 ` cvs-commit at gcc dot gnu dot org
  2004-09-21 18:45 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-15 21:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-15 21:22 -------
*** Bug 17511 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pcarlini at suse dot de


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


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

* [Bug c++/15049] [4.0 Regression] [DR 278/132/216/338/389/319] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
                   ` (4 preceding siblings ...)
  2004-09-15 21:22 ` [Bug c++/15049] [4.0 " pinskia at gcc dot gnu dot org
@ 2004-09-21 17:24 ` cvs-commit at gcc dot gnu dot org
  2004-09-21 18:45 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-09-21 17:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-09-21 17:24 -------
Subject: Bug 15049

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	austern@gcc.gnu.org	2004-09-21 17:24:45

Modified files:
	gcc/cp         : ChangeLog decl.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/other: anon3.C 

Log message:
	PR c++/15049
	* cp/decl.c (grokvardecl): Accept declarations of global variables
	using anonymous types.
	* testsuite/g++.dg/other/anon3.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4372&r2=1.4373
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1300&r2=1.1301
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4326&r2=1.4327
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/anon3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug c++/15049] [4.0 Regression] [DR 278/132/216/338/389/319] global variables with anonymous types are legal
  2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
                   ` (5 preceding siblings ...)
  2004-09-21 17:24 ` cvs-commit at gcc dot gnu dot org
@ 2004-09-21 18:45 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-21 18:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-21 18:45 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2004-09-21 18:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-21 18:08 [Bug c++/15049] New: global variables with anonymous types are legal austern at apple dot com
2004-04-21 18:13 ` [Bug c++/15049] [3.5 Regression] " pinskia at gcc dot gnu dot org
2004-04-30  2:13 ` [Bug c++/15049] [3.5 Regression] [DR 278/132/216/338/389/319] " pinskia at gcc dot gnu dot org
2004-07-22  4:04 ` pinskia at gcc dot gnu dot org
2004-07-22 21:15 ` austern at apple dot com
2004-09-15 21:22 ` [Bug c++/15049] [4.0 " pinskia at gcc dot gnu dot org
2004-09-21 17:24 ` cvs-commit at gcc dot gnu dot org
2004-09-21 18:45 ` pinskia at gcc dot gnu 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).