public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53184] New: Unnecessary anonymous namespace warnings
@ 2012-05-02  6:09 orgads at gmail dot com
  2012-05-02  6:26 ` [Bug c++/53184] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: orgads at gmail dot com @ 2012-05-02  6:09 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53184
           Summary: Unnecessary anonymous namespace warnings
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: orgads@gmail.com


Created attachment 27279
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27279
sample code

The attached file (stripped preprocessor output) produces the following
warning:

foo.cpp:5:16: warning: 'Bar' has a field 'Bar::foo' whose type uses the
anonymous namespace [enabled by default]


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
@ 2012-05-02  6:26 ` pinskia at gcc dot gnu.org
  2012-05-02  6:56 ` orgads at gmail dot com
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-05-02  6:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-05-02 06:25:50 UTC ---
>foo.cpp:5:16: warning: 'Bar' has a field 'Bar::foo' whose type uses the
anonymous namespace [enabled by default]

The warning just needs to be worded better but otherwise it is correct.  It is
using a type which is anonymous.


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
  2012-05-02  6:26 ` [Bug c++/53184] " pinskia at gcc dot gnu.org
@ 2012-05-02  6:56 ` orgads at gmail dot com
  2012-05-02 10:48 ` redi at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: orgads at gmail dot com @ 2012-05-02  6:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Orgad Shaneh <orgads at gmail dot com> 2012-05-02 06:56:28 UTC ---
Anonymous types shouldn't produce any warnings. They are very commonly used in
headers needed for both C and C++ projects. The warning is meant for types
inside anonymous namespaces, which is not the case here.

Moreover, removing the volatile keyword resolves the warning. Why is that?


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
  2012-05-02  6:26 ` [Bug c++/53184] " pinskia at gcc dot gnu.org
  2012-05-02  6:56 ` orgads at gmail dot com
@ 2012-05-02 10:48 ` redi at gcc dot gnu.org
  2012-05-02 17:23 ` jason at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-02 10:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-02 10:48:18 UTC ---
(In reply to comment #2)
> The warning is meant for types
> inside anonymous namespaces, which is not the case here.

Technically it triggers for types with "anon" visibility, which is usually (but
not always) caused by being declared in an anonymous namespace.  Andrew's right
the wording could be improved so it's not misleading in cases such as this.

> Moreover, removing the volatile keyword resolves the warning. Why is that?

Because then the anonymous class has the name "Foo" for linkage purposes, and
has external linkage.  When Foo referes to the const or volatile qualified form
of the class, the anonymous class itself has no name and so no linkage, only
the cv-qualified form has a name for linkage purposes.

I'm not sure if that behaviour is correct though, let's ask Jason


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (2 preceding siblings ...)
  2012-05-02 10:48 ` redi at gcc dot gnu.org
@ 2012-05-02 17:23 ` jason at gcc dot gnu.org
  2013-06-15 18:16 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2012-05-02 17:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2012-05-02 17:23:09 UTC ---
(In reply to comment #3)
> Because then the anonymous class has the name "Foo" for linkage purposes, and
> has external linkage.  When Foo referes to the const or volatile qualified form
> of the class, the anonymous class itself has no name and so no linkage, only
> the cv-qualified form has a name for linkage purposes.
> 
> I'm not sure if that behaviour is correct though, let's ask Jason

Yes, that's right. 7.1.3:

If the typedef declaration defines an unnamed class (or enum), the first
typedef-name declared by the declaration to be that class type (or enum type)
is used to denote the class type (or enum type) for linkage purposes only
(3.5).

  typedef struct { } *ps, S;  // S is the class name for linkage purposes

Adding volatile means that Foo doesn't name the class, it names the volatile
variant of the class, so it isn't the class's name for linkage purposes, so the
class has no linkage.  The warning complains about using a type with no linkage
as a member type in a header file, since including that header in multiple
source files would be an ODR violation as the type Foo is different in each
translation unit.


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (3 preceding siblings ...)
  2012-05-02 17:23 ` jason at gcc dot gnu.org
@ 2013-06-15 18:16 ` paolo.carlini at oracle dot com
  2013-06-16  2:59 ` zeratul976 at hotmail dot com
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-15 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zeratul976 at hotmail dot com

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
*** Bug 54060 has been marked as a duplicate of this bug. ***


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (4 preceding siblings ...)
  2013-06-15 18:16 ` paolo.carlini at oracle dot com
@ 2013-06-16  2:59 ` zeratul976 at hotmail dot com
  2013-06-17 12:41 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: zeratul976 at hotmail dot com @ 2013-06-16  2:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Nathan Ridge <zeratul976 at hotmail dot com> ---
(In reply to Jason Merrill from comment #4)
> (In reply to comment #3)
> > Because then the anonymous class has the name "Foo" for linkage purposes, and
> > has external linkage.  When Foo referes to the const or volatile qualified form
> > of the class, the anonymous class itself has no name and so no linkage, only
> > the cv-qualified form has a name for linkage purposes.
> > 
> > I'm not sure if that behaviour is correct though, let's ask Jason
> 
> Yes, that's right. 7.1.3:
> 
> If the typedef declaration defines an unnamed class (or enum), the first
> typedef-name declared by the declaration to be that class type (or enum
> type) is used to denote the class type (or enum type) for linkage purposes
> only (3.5).
> 
>   typedef struct { } *ps, S;  // S is the class name for linkage purposes
> 
> Adding volatile means that Foo doesn't name the class, it names the volatile
> variant of the class, so it isn't the class's name for linkage purposes, so
> the class has no linkage.  The warning complains about using a type with no
> linkage as a member type in a header file, since including that header in
> multiple source files would be an ODR violation as the type Foo is different
> in each translation unit.

Is this ODR violation an actual problem in practice, with GCC? I find these
warnings annoying to work around, and I wouldn't mind seeing an option to
silence them if they don't indicate an actual problem.


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (5 preceding siblings ...)
  2013-06-16  2:59 ` zeratul976 at hotmail dot com
@ 2013-06-17 12:41 ` redi at gcc dot gnu.org
  2013-06-17 12:43 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-17 12:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I've just come across a case where an option to disable that warning would be
handy: We have a foo.cc file defining some classes in an anon namespace. A unit
test does #include "foo.cc" so it can test the implementation details, which
makes GCC (quite rightly) think it's a header file. In this case no other
translation unit is going to include the "header" and so there will be no ODR
violation, but we can't disable the warning so have to resort to macros to give
the namespace a name when used in this way, which means the test isn't testing
the real code.


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (6 preceding siblings ...)
  2013-06-17 12:41 ` redi at gcc dot gnu.org
@ 2013-06-17 12:43 ` paolo.carlini at oracle dot com
  2013-06-17 12:58 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-17 12:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Somebody could suggest an appropriate name for the warning. Then a patchlet
would be easy to do and also easy to approve I think (naming warnings is in
general a sensible idea)


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (7 preceding siblings ...)
  2013-06-17 12:43 ` paolo.carlini at oracle dot com
@ 2013-06-17 12:58 ` paolo.carlini at oracle dot com
  2015-04-27 19:45 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-17 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> ---
... and of course a clearer wording for the warning itself.


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (8 preceding siblings ...)
  2013-06-17 12:58 ` paolo.carlini at oracle dot com
@ 2015-04-27 19:45 ` paolo.carlini at oracle dot com
  2015-08-19 14:44 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-04-27 19:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53184

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-04-27
                 CC|orgads at gmail dot com            |
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com
     Ever confirmed|0                           |1


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (9 preceding siblings ...)
  2015-04-27 19:45 ` paolo.carlini at oracle dot com
@ 2015-08-19 14:44 ` paolo.carlini at oracle dot com
  2015-09-09 16:48 ` paolo at gcc dot gnu.org
  2015-09-09 16:53 ` paolo.carlini at oracle dot com
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-08-19 14:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53184

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |blue.dragan+gcc at gmail dot com

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> ---
*** Bug 51440 has been marked as a duplicate of this bug. ***


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (10 preceding siblings ...)
  2015-08-19 14:44 ` paolo.carlini at oracle dot com
@ 2015-09-09 16:48 ` paolo at gcc dot gnu.org
  2015-09-09 16:53 ` paolo.carlini at oracle dot com
  12 siblings, 0 replies; 14+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-09-09 16:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53184

--- Comment #11 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Wed Sep  9 16:48:13 2015
New Revision: 227593

URL: https://gcc.gnu.org/viewcvs?rev=227593&root=gcc&view=rev
Log:
2015-09-09  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/53184
        * doc/invoke.texi ([Wsubobject-linkage]): Document.

/c-family
2015-09-09  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/53184
        * c.opt ([Wsubobject-linkage]): Add.

/cp
2015-09-09  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/53184
        * decl2.c (constrain_class_visibility): Use Wsubobject-linkage.

/testsuite
2015-09-09  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/53184
        * g++.dg/warn/Wsubobject-linkage-1.C: New.
        * g++.dg/warn/Wsubobject-linkage-2.C: Likewise.
        * g++.dg/warn/Wsubobject-linkage-3.C: Likewise.
        * g++.dg/warn/Wsubobject-linkage-4.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-1.C
    trunk/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-2.C
    trunk/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C
    trunk/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-4.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c.opt
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/53184] Unnecessary anonymous namespace warnings
  2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
                   ` (11 preceding siblings ...)
  2015-09-09 16:48 ` paolo at gcc dot gnu.org
@ 2015-09-09 16:53 ` paolo.carlini at oracle dot com
  12 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-09-09 16:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53184

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
           Assignee|paolo.carlini at oracle dot com    |unassigned at gcc dot gnu.org
   Target Milestone|---                         |6.0

--- Comment #12 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

end of thread, other threads:[~2015-09-09 16:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-02  6:09 [Bug c++/53184] New: Unnecessary anonymous namespace warnings orgads at gmail dot com
2012-05-02  6:26 ` [Bug c++/53184] " pinskia at gcc dot gnu.org
2012-05-02  6:56 ` orgads at gmail dot com
2012-05-02 10:48 ` redi at gcc dot gnu.org
2012-05-02 17:23 ` jason at gcc dot gnu.org
2013-06-15 18:16 ` paolo.carlini at oracle dot com
2013-06-16  2:59 ` zeratul976 at hotmail dot com
2013-06-17 12:41 ` redi at gcc dot gnu.org
2013-06-17 12:43 ` paolo.carlini at oracle dot com
2013-06-17 12:58 ` paolo.carlini at oracle dot com
2015-04-27 19:45 ` paolo.carlini at oracle dot com
2015-08-19 14:44 ` paolo.carlini at oracle dot com
2015-09-09 16:48 ` paolo at gcc dot gnu.org
2015-09-09 16:53 ` paolo.carlini at oracle dot com

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).