* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
@ 2009-11-06 14:09 ` redi at gcc dot gnu dot org
2009-11-06 15:30 ` igodard at pacbell dot net
` (19 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-11-06 14:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from redi at gcc dot gnu dot org 2009-11-06 14:09 -------
Both declarations are at namespace-scope (see [basic.scope.namespace]) not
local scope (see [basic.scope.local]) so I think "non-local" is fine
--
redi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
2009-11-06 14:09 ` [Bug c++/41970] " redi at gcc dot gnu dot org
@ 2009-11-06 15:30 ` igodard at pacbell dot net
2009-11-06 15:43 ` redi at gcc dot gnu dot org
` (18 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: igodard at pacbell dot net @ 2009-11-06 15:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from igodard at pacbell dot net 2009-11-06 15:30 -------
OK, I read the standard sections cited and understand.
Then I'll reopen this to ask the deeper question: why do either deserve a
warning in the first place?
--
igodard at pacbell dot net changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
2009-11-06 14:09 ` [Bug c++/41970] " redi at gcc dot gnu dot org
2009-11-06 15:30 ` igodard at pacbell dot net
@ 2009-11-06 15:43 ` redi at gcc dot gnu dot org
2009-11-06 15:48 ` redi at gcc dot gnu dot org
` (17 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-11-06 15:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from redi at gcc dot gnu dot org 2009-11-06 15:43 -------
(In reply to comment #2)
> Then I'll reopen this to ask the deeper question: why do either deserve a
> warning in the first place?
Good question - they probably should be fatal errors :-)
[basic.link]/8
"A name with no linkage (notably, the name of a class or enumeration declared
in a local scope (3.3.2)) shall not be used to declare an entity with linkage."
The anonymous enumeration types have no linkage, but one could argue that since
they are anonymous they are not "names with no linkage" but I think it's still
invalid. If A and D have external linkage then they could be referred to from
another translation unit, but that is not possible because their type cannot be
named from another translation unit.
You can make it valid by giving the variables internal linkage:
enum {a, b, c} static A = a;
namespace {
enum {d, e, f} static D = d;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (2 preceding siblings ...)
2009-11-06 15:43 ` redi at gcc dot gnu dot org
@ 2009-11-06 15:48 ` redi at gcc dot gnu dot org
2009-11-06 18:22 ` igodard at pacbell dot net
` (16 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-11-06 15:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from redi at gcc dot gnu dot org 2009-11-06 15:48 -------
Or rather,
static enum {a, b, c} A = a;
namespace {
static enum {d, e, f} D = d;
}
In any case, the warning is telling you that an object with external linkage
cannot be referred to in other translation units, so external linkage may not
be appropriate
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (3 preceding siblings ...)
2009-11-06 15:48 ` redi at gcc dot gnu dot org
@ 2009-11-06 18:22 ` igodard at pacbell dot net
2009-11-06 18:27 ` redi at gcc dot gnu dot org
` (15 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: igodard at pacbell dot net @ 2009-11-06 18:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from igodard at pacbell dot net 2009-11-06 18:22 -------
That argument (warn about unreferenceable names with external linkage) applies
here to enum A. However, because enum D is inside the anonymous namespace it
cannot be referenced from another unit anyway and so must have local (i.e.
static) linkage. Hence, as suggested by my original report, it seems reasonable
that there should be no warning on D.
Or am I misunderstanding the implications of the anonymous namespace, which I
had understood to be the C++ replacement for C's "static"? That is, in your
second example, isn't the "static" on D redundant?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (4 preceding siblings ...)
2009-11-06 18:22 ` igodard at pacbell dot net
@ 2009-11-06 18:27 ` redi at gcc dot gnu dot org
2009-11-06 18:30 ` redi at gcc dot gnu dot org
` (14 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-11-06 18:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from redi at gcc dot gnu dot org 2009-11-06 18:27 -------
Members of anonymous namespaces do not necessarily have internal linkage,
that's the point. They are local to a translation unit, but can still have
external linkage.
N.B. for GCC 4.2 and later "Members of the anonymous namespace are now local to
a particular translation unit, along with any other declarations which use
them, though they are still treated as having external linkage for language
semantics."
>From http://gcc.gnu.org/gcc-4.2/changes.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (5 preceding siblings ...)
2009-11-06 18:27 ` redi at gcc dot gnu dot org
@ 2009-11-06 18:30 ` redi at gcc dot gnu dot org
2010-01-10 22:04 ` matt at use dot net
` (13 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-11-06 18:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from redi at gcc dot gnu dot org 2009-11-06 18:30 -------
N.B. Comeau's online compiler gives an error for both variable definitions
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (6 preceding siblings ...)
2009-11-06 18:30 ` redi at gcc dot gnu dot org
@ 2010-01-10 22:04 ` matt at use dot net
2010-01-10 22:24 ` igodard at pacbell dot net
` (12 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: matt at use dot net @ 2010-01-10 22:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from matt at use dot net 2010-01-10 22:04 -------
Created an attachment (id=19531)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19531&action=view)
pre-processed output of the file that emitted the false positive using the
commandline mentioned in my comment
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (7 preceding siblings ...)
2010-01-10 22:04 ` matt at use dot net
@ 2010-01-10 22:24 ` igodard at pacbell dot net
2010-01-11 18:46 ` manu at gcc dot gnu dot org
` (11 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: igodard at pacbell dot net @ 2010-01-10 22:24 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
------- Comment #9 from igodard at pacbell dot net 2010-01-10 22:23 -------
Comeau gives this diagnostic:
"ComeauTest.c", line 1: error: use of a type with no linkage to declare a
variable
with linkage
enum {a, b, c} A = a;
^
This message give the true nature of the problem, whereas the gcc message:
foo.cc:1: warning: non-local variable <anonymous enum> A uses anonymous
type
requires six posts from experts to explain.
Please recategorize this report as "diagnostic quality", confirm, and assign
it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (8 preceding siblings ...)
2010-01-10 22:24 ` igodard at pacbell dot net
@ 2010-01-11 18:46 ` manu at gcc dot gnu dot org
2010-01-11 18:52 ` manu at gcc dot gnu dot org
` (10 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-01-11 18:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from manu at gcc dot gnu dot org 2010-01-11 18:46 -------
(From update of attachment 19531)
This file has nothing to do with this bug.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #19531|0 |1
is obsolete| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] Unjustified "anonymous type" warning
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (9 preceding siblings ...)
2010-01-11 18:46 ` manu at gcc dot gnu dot org
@ 2010-01-11 18:52 ` manu at gcc dot gnu dot org
2010-01-11 18:54 ` [Bug c++/41970] use of a type with no linkage to declare a variable with linkage manu at gcc dot gnu dot org
` (9 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-01-11 18:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from manu at gcc dot gnu dot org 2010-01-11 18:52 -------
(In reply to comment #9)
> Please recategorize this report as "diagnostic quality", confirm, and assign
> it.
Bugs are not assigned, they are taken. But confirmed it is. Patches welcome.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2010-01-11 18:52:09
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (10 preceding siblings ...)
2010-01-11 18:52 ` manu at gcc dot gnu dot org
@ 2010-01-11 18:54 ` manu at gcc dot gnu dot org
2010-01-12 1:00 ` redi at gcc dot gnu dot org
` (8 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-01-11 18:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from manu at gcc dot gnu dot org 2010-01-11 18:54 -------
Comeau rejects it. Is this accepts-invalid, then?
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Unjustified "anonymous type"|use of a type with no
|warning |linkage to declare a
| |variable with linkage
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (11 preceding siblings ...)
2010-01-11 18:54 ` [Bug c++/41970] use of a type with no linkage to declare a variable with linkage manu at gcc dot gnu dot org
@ 2010-01-12 1:00 ` redi at gcc dot gnu dot org
2010-01-12 1:08 ` redi at gcc dot gnu dot org
` (7 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-01-12 1:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #13 from redi at gcc dot gnu dot org 2010-01-12 01:00 -------
(In reply to comment #12)
> Comeau rejects it. Is this accepts-invalid, then?
>
I think so, as I suggested in comment 3
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (12 preceding siblings ...)
2010-01-12 1:00 ` redi at gcc dot gnu dot org
@ 2010-01-12 1:08 ` redi at gcc dot gnu dot org
2010-01-12 1:12 ` igodard at pacbell dot net
` (6 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-01-12 1:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #14 from redi at gcc dot gnu dot org 2010-01-12 01:08 -------
(In reply to comment #9)
> requires six posts from experts to explain.
I'm not sure where you got that number, after my second comment I was
correcting my own typos or your misunderstanding of unnamed namespaces :)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (13 preceding siblings ...)
2010-01-12 1:08 ` redi at gcc dot gnu dot org
@ 2010-01-12 1:12 ` igodard at pacbell dot net
2010-01-12 10:16 ` manu at gcc dot gnu dot org
` (5 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: igodard at pacbell dot net @ 2010-01-12 1:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #15 from igodard at pacbell dot net 2010-01-12 01:12 -------
Should I submit a second report so there is one for "accepts invalid" and a
different one for "diagnostic quality"?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (14 preceding siblings ...)
2010-01-12 1:12 ` igodard at pacbell dot net
@ 2010-01-12 10:16 ` manu at gcc dot gnu dot org
2010-01-20 23:32 ` jason at gcc dot gnu dot org
` (4 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-01-12 10:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #16 from manu at gcc dot gnu dot org 2010-01-12 10:16 -------
(In reply to comment #15)
> Should I submit a second report so there is one for "accepts invalid" and a
> different one for "diagnostic quality"?
>
No need, thanks. Both can be solved at the same time.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (15 preceding siblings ...)
2010-01-12 10:16 ` manu at gcc dot gnu dot org
@ 2010-01-20 23:32 ` jason at gcc dot gnu dot org
2010-01-20 23:36 ` jason at gcc dot gnu dot org
` (3 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-01-20 23:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #17 from jason at gcc dot gnu dot org 2010-01-20 23:32 -------
We accept this testcase with a warning because it is both common and harmless.
In 4.5, this testcase will be accepted with no warning in -std=c++0x mode, as
we now implement DR 757.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jason at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2010-01-11 18:52:09 |2010-01-20 23:32:16
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (16 preceding siblings ...)
2010-01-20 23:32 ` jason at gcc dot gnu dot org
@ 2010-01-20 23:36 ` jason at gcc dot gnu dot org
2010-02-19 21:39 ` jason at gcc dot gnu dot org
` (2 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-01-20 23:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #18 from jason at gcc dot gnu dot org 2010-01-20 23:36 -------
So, removing the accepts-invalid keyword. I'll fix the diagnostic in 4.6.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|accepts-invalid |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (17 preceding siblings ...)
2010-01-20 23:36 ` jason at gcc dot gnu dot org
@ 2010-02-19 21:39 ` jason at gcc dot gnu dot org
2010-04-07 15:55 ` jason at gcc dot gnu dot org
2010-05-04 4:56 ` jason at gcc dot gnu dot org
20 siblings, 0 replies; 22+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-02-19 21:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #19 from jason at gcc dot gnu dot org 2010-02-19 21:39 -------
Created an attachment (id=19925)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19925&action=view)
patch for 4.6
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (18 preceding siblings ...)
2010-02-19 21:39 ` jason at gcc dot gnu dot org
@ 2010-04-07 15:55 ` jason at gcc dot gnu dot org
2010-05-04 4:56 ` jason at gcc dot gnu dot org
20 siblings, 0 replies; 22+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-07 15:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #20 from jason at gcc dot gnu dot org 2010-04-07 15:54 -------
Subject: Bug 41970
Author: jason
Date: Wed Apr 7 15:54:17 2010
New Revision: 158071
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158071
Log:
PR c++/41970
* decl.c (grokvardecl): Tweak warning message.
(grokfndecl): Likewise.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.old-deja/g++.other/linkage1.C
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Bug c++/41970] use of a type with no linkage to declare a variable with linkage
2009-11-06 13:45 [Bug c++/41970] New: Unjustified "anonymous type" warning igodard at pacbell dot net
` (19 preceding siblings ...)
2010-04-07 15:55 ` jason at gcc dot gnu dot org
@ 2010-05-04 4:56 ` jason at gcc dot gnu dot org
20 siblings, 0 replies; 22+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-05-04 4:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #21 from jason at gcc dot gnu dot org 2010-05-04 04:56 -------
Fixed for 4.6.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.6.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41970
^ permalink raw reply [flat|nested] 22+ messages in thread