public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28514]  New: pch vs. anonymous namespaces
@ 2006-07-27 17:02 bkoz at gcc dot gnu dot org
  2006-07-27 17:04 ` [Bug c++/28514] " bkoz at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-07-27 17:02 UTC (permalink / raw)
  To: gcc-bugs

Am running into this kind of thing when I convert include/ext/rope and friends
to using anonymous namespace.

This simplified source doesn't show the bug, sadly, but I'll put up
pre-processed code that demonstrates it in a bit.

namespace __gnu_cxx
{
  namespace 
  {
    enum _Tag1 {_S_leaf1, _S_concat1, _S_substringfn1, _S_function1};
  }

  namespace constants
  {
    enum _Tag2 {_S_leaf2, _S_concat2, _S_substringfn2, _S_function2};
  }

  template<typename T>
  struct A
  {
    static void foo(const T i)
    {    
      int j;
      switch(i)
        {
        case _S_concat1: // error here, invalid integer constant
          j = 5;
          break;
        case constants::_S_leaf2:
          j = 5;
          break;
        default:
          j = 0;
        }
    }
  };

Code seems correct, but something about PCH kills it.


-- 
           Summary: pch vs. anonymous namespaces
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bkoz at gcc dot gnu dot org


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


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

* [Bug c++/28514] pch vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
@ 2006-07-27 17:04 ` bkoz at gcc dot gnu dot org
  2006-07-27 17:05 ` bkoz at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-07-27 17:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bkoz at gcc dot gnu dot org  2006-07-27 17:04 -------
Created an attachment (id=11957)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11957&action=view)
reproducer with today's gcc


To reproduce, do:

/mnt/share/bld/gcc/./gcc/xgcc -shared-libgcc -B/mnt/share/bld/gcc/./gcc
-nostdinc++ -Winvalid-pch -Wno-deprecated -x c++-header
i686-pc-linux-gnu/bits/extc++.h.gch.ii -o
i686-pc-linux-gnu/bits/extc++.h.gch/02g.gch

Or equivalent, based on your current build compiler directory locations.

Get:

/mnt/share/bld/gcc/i686-pc-linux-gnu/libstdc++-v3/include/ext/ropeimpl.h: In
static member function 'static _CharT __gnu_cxx::rope<_CharT,
_Alloc>::_S_fetch(__gnu_cxx::_Rope_RopeRep<_CharT, _Alloc>*, size_t) [with
_CharT = char, _Alloc = std::allocator<char>]':
/mnt/share/bld/gcc/i686-pc-linux-gnu/libstdc++-v3/include/ext/rope:1980:  
instantiated from '_CharT __gnu_cxx::rope<_CharT, _Alloc>::operator[](size_t)
const [with _CharT = char, _Alloc = std::allocator<char>]'
/mnt/share/bld/gcc/i686-pc-linux-gnu/libstdc++-v3/include/ext/rope:2894:  
instantiated from here
/mnt/share/bld/gcc/i686-pc-linux-gnu/libstdc++-v3/include/ext/ropeimpl.h:1334:
error: case label does not reduce to an integer constant


-- 


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


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

* [Bug c++/28514] pch vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
  2006-07-27 17:04 ` [Bug c++/28514] " bkoz at gcc dot gnu dot org
@ 2006-07-27 17:05 ` bkoz at gcc dot gnu dot org
  2006-07-27 22:32 ` bkoz at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-07-27 17:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bkoz at gcc dot gnu dot org  2006-07-27 17:05 -------

Jason can you look at this plz?


-- 

bkoz 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                     |


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


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

* [Bug c++/28514] pch vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
  2006-07-27 17:04 ` [Bug c++/28514] " bkoz at gcc dot gnu dot org
  2006-07-27 17:05 ` bkoz at gcc dot gnu dot org
@ 2006-07-27 22:32 ` bkoz at gcc dot gnu dot org
  2006-07-27 22:33 ` bkoz at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-07-27 22:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bkoz at gcc dot gnu dot org  2006-07-27 22:32 -------

Changing just the first

            case _S_concat:

to

            case ::_S_concat:

Fixes this. Wierd.

I noticed a couple of other random lookup issues, or non-issues that surprised
me. One was with static functions in global-scope anonymous namespaces have to
be explicitly qualified with a :: operator. (mt_allocator.cc patches)

global-scope enums used as integer constants in case labels of switch
statements. Fully qualified too?

Anyway. I'll attach the work-in-progress patch to convert libstdc++
__gnu_internal namespace to anonymous namespaces.

-benjamin


-- 


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


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

* [Bug c++/28514] pch vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2006-07-27 22:32 ` bkoz at gcc dot gnu dot org
@ 2006-07-27 22:33 ` bkoz at gcc dot gnu dot org
  2006-07-27 22:34 ` [Bug c++/28514] libstdc++ " bkoz at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-07-27 22:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bkoz at gcc dot gnu dot org  2006-07-27 22:33 -------
Created an attachment (id=11961)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11961&action=view)
work-in-progress patch to convert libstdc++ to anonymous namespaces


-- 


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


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

* [Bug c++/28514] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2006-07-27 22:33 ` bkoz at gcc dot gnu dot org
@ 2006-07-27 22:34 ` bkoz at gcc dot gnu dot org
  2006-07-29  5:25 ` [Bug c++/28514] [4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-07-27 22:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bkoz at gcc dot gnu dot org  2006-07-27 22:33 -------

change title


-- 

bkoz at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|pch vs. anonymous namespaces|libstdc++ vs. anonymous
                   |                            |namespaces


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


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

* [Bug c++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2006-07-27 22:34 ` [Bug c++/28514] libstdc++ " bkoz at gcc dot gnu dot org
@ 2006-07-29  5:25 ` pinskia at gcc dot gnu dot org
  2006-07-31  8:16 ` jason at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-07-29  5:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2006-07-29 05:25 -------
I think this is 4.2 regression now but I need to reduce it.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|libstdc++ vs. anonymous     |[4.2 Regression] libstdc++
                   |namespaces                  |vs. anonymous namespaces
   Target Milestone|---                         |4.2.0


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


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

* [Bug c++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2006-07-29  5:25 ` [Bug c++/28514] [4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-07-31  8:16 ` jason at gcc dot gnu dot org
  2006-07-31  8:20 ` jason at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-07-31  8:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2006-07-31 08:16 -------
The testcase gives the same errors for me when compiled as normal C++ as in PCH
mode.

The problem seems to be that you're removing the Rope_constants namespace name
and creating a name lookup collision between the _S_concat enumerator and the
_S_concat function in rope.

Why would you want to mess with Rope_constants, anyway?  It doesn't have any
symbols in it, it just controls name lookup.  When you take it away, name
lookup changes, and things blow up.  Moving them to the anonymous namespace has
the same effect for name lookup as declaring them directly in __gnu_cxx.

Furthermore, defining _Tag in an anonymous namespace will cause the compiler to
give all functions with _Tag in their signature internal linkage.  I don't
understand why you would want this.


-- 

jason at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2006-07-31  8:16 ` jason at gcc dot gnu dot org
@ 2006-07-31  8:20 ` jason at gcc dot gnu dot org
  2006-09-04 15:22 ` bkoz at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-07-31  8:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jason at gcc dot gnu dot org  2006-07-31 08:20 -------
In general, I think using the anonymous namespace in headers is not what you
want.


-- 


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


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

* [Bug c++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2006-07-31  8:20 ` jason at gcc dot gnu dot org
@ 2006-09-04 15:22 ` bkoz at gcc dot gnu dot org
  2006-09-07  0:14 ` jason at redhat dot com
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-09-04 15:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from bkoz at gcc dot gnu dot org  2006-09-04 15:22 -------

> Furthermore, defining _Tag in an anonymous namespace will cause the compiler to
> give all functions with _Tag in their signature internal linkage.  I don't
> understand why you would want this.

This is precisely one reason why anonymous namespaces are useful. It provides a
very viceral way to sanity check an API. Make sure that the private parts
really are private, say.

Please, let's leave <rope> out of it.

I think that there are good reasons to use anonymous namespaces in headers,
even if you disagree with these designs personally.


-benjamin


-- 


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


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

* [Bug c++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2006-09-04 15:22 ` bkoz at gcc dot gnu dot org
@ 2006-09-07  0:14 ` jason at redhat dot com
  2006-10-17 11:49 ` bkoz at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jason at redhat dot com @ 2006-09-07  0:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jason at redhat dot com  2006-09-07 00:14 -------
Subject: Re:  [4.2 Regression] libstdc++ vs. anonymous namespaces

bkoz at gcc dot gnu dot org wrote:
> This is precisely one reason why anonymous namespaces are useful. It provides a
> very viceral way to sanity check an API. Make sure that the private parts
> really are private, say.

Yes, but there's a difference between private and internal.  This is 
especially problematic for templates; if you give template 
instantiations internal linkage, we can't share them between translation 
units anymore and you get code bloat.  Do you really want a copy of the 
list of primes from the hashtable policy code in each translation unit 
that uses it?

It seems to me that Rope_constants, _Private in <tr1/random> and the 
hashtable policy stuff were in special namespaces just to avoid name 
lookup pollution.  If you really want them also to be unique to each 
translation unit you could insert an anonymous namespace inside the 
preexisting namespace and not have to mess with name lookup at all.

I thought after my earlier comments you would put Rope_constants back, 
but now that I actually look at what you checked in I see that you just 
added explicit global scope to the uses.  That kind of cluttering up of 
the global namespace seems like a mistake to me; _Tag isn't a very 
unique name.  Changing _Private to an anonymous namespace has the same 
problem, except it's only cluttering up tr1 instead of the global 
namespace.  In both cases inserting an anonymous namespace inside the 
named namespace seems both better and less work.

> Please, let's leave <rope> out of it.

You reported a problem compiling <rope>, it's hard to respond without 
talking about <rope>.

> I think that there are good reasons to use anonymous namespaces in headers,
> even if you disagree with these designs personally.

Please elaborate.  Why do you want _Tag, _Select, X::primes, etc. to be 
unique to each translation unit?

Jason


-- 


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


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

* [Bug c++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2006-09-07  0:14 ` jason at redhat dot com
@ 2006-10-17 11:49 ` bkoz at gcc dot gnu dot org
  2006-10-17 11:52 ` [Bug libstdc++/28514] " bkoz at gcc dot gnu dot org
  2006-10-17 11:56 ` bkoz at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-10-17 11:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from bkoz at gcc dot gnu dot org  2006-10-17 11:48 -------

OK. I've reverted these anonymous namespace conversions.

Namespace that are just trying to squester name lookup should be spelled as
nested "detail" namespaces. Namespaces that are trying to prohibit exports via
internal linkage should be anonymous namespaces. 

I believe this usage is now uniform.


-- 


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


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

* [Bug libstdc++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (10 preceding siblings ...)
  2006-10-17 11:49 ` bkoz at gcc dot gnu dot org
@ 2006-10-17 11:52 ` bkoz at gcc dot gnu dot org
  2006-10-17 11:56 ` bkoz at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-10-17 11:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from bkoz at gcc dot gnu dot org  2006-10-17 11:52 -------

Should be libstdc++ bug.


-- 

bkoz at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++


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


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

* [Bug libstdc++/28514] [4.2 Regression] libstdc++ vs. anonymous namespaces
  2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
                   ` (11 preceding siblings ...)
  2006-10-17 11:52 ` [Bug libstdc++/28514] " bkoz at gcc dot gnu dot org
@ 2006-10-17 11:56 ` bkoz at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: bkoz at gcc dot gnu dot org @ 2006-10-17 11:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from bkoz at gcc dot gnu dot org  2006-10-17 11:56 -------
Subject: Bug 28514

Author: bkoz
Date: Tue Oct 17 11:56:21 2006
New Revision: 117824

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117824
Log:
2006-10-17  Benjamin Kosnik  <bkoz@redhat.com>

        PR libstdc++/28514 
        * include/bits/cpp_type_traits.h (__detail): Uglify namespace.
        * include/ext/rope: Remove global-scope anonymous namespace, use
        nested __detail. Fixup resulting formatting issues.
        * include/ext/ropeimpl.h: Same.
        * include/tr1/hashtable_policy.h: Remove anonymous namespace
        nesting for __detail.
        * include/tr1/random: Revert anonymous namespace to nested
        __detail namespace.
        * include/tr1/random.tcc: Same.
        * src/ext-inst.cc: Fixups for above.


Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/cpp_type_traits.h
    trunk/libstdc++-v3/include/ext/rope
    trunk/libstdc++-v3/include/ext/ropeimpl.h
    trunk/libstdc++-v3/include/tr1/hashtable_policy.h
    trunk/libstdc++-v3/include/tr1/random
    trunk/libstdc++-v3/include/tr1/random.tcc
    trunk/libstdc++-v3/src/ext-inst.cc


-- 


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


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

end of thread, other threads:[~2006-10-17 11:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-27 17:02 [Bug c++/28514] New: pch vs. anonymous namespaces bkoz at gcc dot gnu dot org
2006-07-27 17:04 ` [Bug c++/28514] " bkoz at gcc dot gnu dot org
2006-07-27 17:05 ` bkoz at gcc dot gnu dot org
2006-07-27 22:32 ` bkoz at gcc dot gnu dot org
2006-07-27 22:33 ` bkoz at gcc dot gnu dot org
2006-07-27 22:34 ` [Bug c++/28514] libstdc++ " bkoz at gcc dot gnu dot org
2006-07-29  5:25 ` [Bug c++/28514] [4.2 Regression] " pinskia at gcc dot gnu dot org
2006-07-31  8:16 ` jason at gcc dot gnu dot org
2006-07-31  8:20 ` jason at gcc dot gnu dot org
2006-09-04 15:22 ` bkoz at gcc dot gnu dot org
2006-09-07  0:14 ` jason at redhat dot com
2006-10-17 11:49 ` bkoz at gcc dot gnu dot org
2006-10-17 11:52 ` [Bug libstdc++/28514] " bkoz at gcc dot gnu dot org
2006-10-17 11:56 ` bkoz 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).