Bug 18604 - [3.4/4.0/4.1 Regression] Use of unqualified names conflict with names in global namespace
Summary: [3.4/4.0/4.1 Regression] Use of unqualified names conflict with names in glob...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.0.0
: P1 normal
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2004-11-22 05:02 UTC by Giovanni Bajo
Modified: 2005-05-10 09:42 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-05-08 22:13:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giovanni Bajo 2004-11-22 05:02:09 UTC
The following code fails to compile on 3.4 and newer compilers:

-------------------------------------------------
#include <functional>

struct less : public std::less<int>
{};

#include <set>
-------------------------------------------------

$ g++-3.4 -c test.cc
In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.0/include/c++/set:67,
                 from test.cc:6:
/usr/lib/gcc/i686-pc-cygwin/3.4.0/include/c++/bits/stl_set.h:69: error: `less' h
as not been declared



The problem appears related to strong using. This is a reduced, epurated 
testcase:

-------------------------------------------------
namespace NB {}

namespace NA  {
    using namespace NB;
}

namespace NB {
    using namespace NA __attribute__ ((strong));

    struct Foo {};
}

struct Foo : NB::Foo
{};

namespace NA {
   Foo a;
}
-------------------------------------------------
test.ii:17: error: `Foo' does not name a type


(note: I found this bug while cleaning up the testcase in PR 15855).

Jason: can you have a look at this please?
Comment 1 Andrew Pinski 2004-11-22 05:10:24 UTC
I think the problem is that the attribute strong is not strong enough.
Comment 2 Giovanni Bajo 2004-12-30 11:59:27 UTC
This affects Boost, I'm bumping the priority.
Comment 3 Mark Mitchell 2005-01-19 06:17:43 UTC
Jason, are you looking at this PR?
Comment 4 Giovanni Bajo 2005-02-07 10:40:05 UTC
Reconfirmed. I see this failure many times in boost logs.
Comment 5 Mark Mitchell 2005-02-11 17:23:18 UTC
Jason, will you be able to look into this PR?
Comment 6 Giovanni Bajo 2005-05-08 22:13:30 UTC
Reconfirmed, still several failures in Boost because of this.
Comment 7 Giovanni Bajo 2005-05-09 07:25:38 UTC
I analyzed this PR again. The problem seems not related to attribute strong 
itself, but rather the way v3 namespaces work. Basically, without debug 
support, the failing code looks like:

---------------------------------
namespace std {
   struct A {};
};

struct A;

namespace std {
   A a;    // std::A, OK!
};
---------------------------------

Instead, with debug support, we end up with code like this:

---------------------------------
namespace std {
   struct A {};
};

namespace __gnu_norm {
   using namespace std;
};

struct A;

namespace __gnu_norm {
   A a;    // ambiguous!
};
---------------------------------

hence the failure. There are at least two ways to fix this in v3:

- Fully qualify all references to std names from code within namespace 
_GLIBCXX_STD (which expands to __gnu_norm in debug mode). This is hard because 
it's impossible to fully check it, and it's pervasive. E.g. bits/stl_set.h:69, 
use "std::less" instead of "less".

- Define namespace __gnu_norm within namespace std. This could be easier 
because you probably have to touch *only* namespace definitions.

Comments?
Comment 8 Paolo Carlini 2005-05-09 09:04:47 UTC
> - Fully qualify all references to std names from code within namespace 
> _GLIBCXX_STD (which expands to __gnu_norm in debug mode). This is hard because 
> it's impossible to fully check it, and it's pervasive. E.g. bits/stl_set.h:69, 
> use "std::less" instead of "less".

Actually, this is already the case (modulo mistakes): we did this work a lot
of time ago, *before* the strong using work. The only remaining occurrences of 
unqualified names are fixed as we find them (Jonathan is doing a great job
here, and in fact he uses debug mode) or are there for a reason: if I remember 
correctly, this is the case of less<>. I'm pretty sure Gaby said something.
Gaby? In case fixing that would be trivial, of course.
Comment 9 Paolo Carlini 2005-05-09 09:16:32 UTC
I found something in the archive:

  http://gcc.gnu.org/ml/libstdc++/2002-12/msg00009.html

That's why we didn't qualify less & co... In mainline (vs v7-branch), where we
still don't have anything special for those function objects, maybe we should
add the qualifications?
Comment 10 Giovanni Bajo 2005-05-09 12:18:01 UTC
There are others unqualified names as default template parmaters, for 
instance "allocator". A good testcase would be something like:

----------------------------------
struct less;
struct allocator;
struct vector;
struct set;
struct pair;
struct map;

/*....*/

#include <set>
#include <vector>
#include <map>
#include <functional>

/*....*/
----------------------------------

which should compile without errors.
Comment 11 Paolo Carlini 2005-05-09 12:29:01 UTC
I see, thanks. Indeed, I don't remember having paid attention to default template
arguments. Let's wait a bit for Gaby's opinion on the whole issue, and, in case,
let's quickly fix those problems.
Comment 12 Mark Mitchell 2005-05-10 01:36:51 UTC
I saw a lot of recent traffic on this issue.

As we're going to be releasing 3.4.4 soon, please commit any changes to the 3.4
branch ASAP.
Comment 13 Paolo Carlini 2005-05-10 01:41:56 UTC
Hi Mark. Actually, I think we are going to fix this only in 4_0/mainline. Other,
similar, fixes went only to mainline/4_0 and the patch that goes in 4_0/mainline
has *lots* of rejects in 3_4. 
Comment 14 Paolo Carlini 2005-05-10 01:43:28 UTC
Also, it's *incorrect* to call this a "3.4 Regression" because happens only in
debug-mode and debug-mode didn't exist at all before 3.4.
Comment 15 Mark Mitchell 2005-05-10 01:52:23 UTC
Fixed in 4.0.1; will not be fixed in 3.4.x.
Comment 16 GCC Commits 2005-05-10 01:58:35 UTC
Subject: Bug 18604

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2005-05-10 01:58:21

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/std: std_bitset.h 
	libstdc++-v3/include/bits: deque.tcc stl_bvector.h stl_deque.h 
	                           stl_list.h stl_map.h stl_multimap.h 
	                           stl_multiset.h stl_set.h stl_vector.h 
	                           vector.tcc 
Added files:
	libstdc++-v3/testsuite/23_containers/bitset: 18604.cc 
	libstdc++-v3/testsuite/23_containers/deque: 18604.cc 
	libstdc++-v3/testsuite/23_containers/list: 18604.cc 
	libstdc++-v3/testsuite/23_containers/map: 18604.cc 
	libstdc++-v3/testsuite/23_containers/set: 18604.cc 
	libstdc++-v3/testsuite/23_containers/vector: 18604.cc 

Log message:
	2005-05-09  Paolo Carlini  <pcarlini@suse.de>
	Giovanni Bajo  <giovannibajo@gcc.gnu.org>
	
	PR libstdc++/18604
	* include/bits/deque.tcc: Fully qualify names from namespace std.
	* include/bits/stl_bvector.h: Likewise.
	* include/bits/stl_deque.h: Likewise.
	* include/bits/stl_list.h: Likewise.
	* include/bits/stl_map.h: Likewise.
	* include/bits/stl_multimap.h: Likewise.
	* include/bits/stl_multiset.h: Likewise.
	* include/bits/stl_set.h: Likewise.
	* include/bits/stl_vector.h: Likewise.
	* include/bits/vector.tcc: Likewise.
	* include/std/std_bitset.h: Likewise.
	* testsuite/23_containers/bitset/18604.cc: New.
	* testsuite/23_containers/deque/18604.cc: Likewise.
	* testsuite/23_containers/list/18604.cc: Likewise.
	* testsuite/23_containers/map/18604.cc: Likewise.
	* testsuite/23_containers/set/18604.cc: Likewise.
	* testsuite/23_containers/vector/18604.cc: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2994&r2=1.2995
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/std/std_bitset.h.diff?cvsroot=gcc&r1=1.28&r2=1.29
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/bitset/18604.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/deque/18604.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/list/18604.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/map/18604.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/set/18604.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/vector/18604.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/deque.tcc.diff?cvsroot=gcc&r1=1.20&r2=1.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_bvector.h.diff?cvsroot=gcc&r1=1.41&r2=1.42
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_deque.h.diff?cvsroot=gcc&r1=1.56&r2=1.57
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_list.h.diff?cvsroot=gcc&r1=1.47&r2=1.48
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_map.h.diff?cvsroot=gcc&r1=1.25&r2=1.26
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_multimap.h.diff?cvsroot=gcc&r1=1.24&r2=1.25
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_multiset.h.diff?cvsroot=gcc&r1=1.24&r2=1.25
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_set.h.diff?cvsroot=gcc&r1=1.23&r2=1.24
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_vector.h.diff?cvsroot=gcc&r1=1.53&r2=1.54
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/vector.tcc.diff?cvsroot=gcc&r1=1.22&r2=1.23

Comment 17 GCC Commits 2005-05-10 02:16:00 UTC
Subject: Bug 18604

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	paolo@gcc.gnu.org	2005-05-10 02:15:43

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/std: std_bitset.h 
	libstdc++-v3/include/bits: deque.tcc stl_bvector.h stl_deque.h 
	                           stl_list.h stl_map.h stl_multimap.h 
	                           stl_multiset.h stl_set.h stl_vector.h 
	                           vector.tcc 
Added files:
	libstdc++-v3/testsuite/23_containers/bitset: 18604.cc 
	libstdc++-v3/testsuite/23_containers/deque: 18604.cc 
	libstdc++-v3/testsuite/23_containers/list: 18604.cc 
	libstdc++-v3/testsuite/23_containers/map: 18604.cc 
	libstdc++-v3/testsuite/23_containers/set: 18604.cc 
	libstdc++-v3/testsuite/23_containers/vector: 18604.cc 

Log message:
	2005-05-09  Paolo Carlini  <pcarlini@suse.de>
	Giovanni Bajo  <giovannibajo@gcc.gnu.org>
	
	PR libstdc++/18604
	* include/bits/deque.tcc: Fully qualify names from namespace std.
	* include/bits/stl_bvector.h: Likewise.
	* include/bits/stl_deque.h: Likewise.
	* include/bits/stl_list.h: Likewise.
	* include/bits/stl_map.h: Likewise.
	* include/bits/stl_multimap.h: Likewise.
	* include/bits/stl_multiset.h: Likewise.
	* include/bits/stl_set.h: Likewise.
	* include/bits/stl_vector.h: Likewise.
	* include/bits/vector.tcc: Likewise.
	* include/std/std_bitset.h: Likewise.
	* testsuite/23_containers/bitset/18604.cc: New.
	* testsuite/23_containers/deque/18604.cc: Likewise.
	* testsuite/23_containers/list/18604.cc: Likewise.
	* testsuite/23_containers/map/18604.cc: Likewise.
	* testsuite/23_containers/set/18604.cc: Likewise.
	* testsuite/23_containers/vector/18604.cc: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.2917.2.44&r2=1.2917.2.45
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/std/std_bitset.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.28&r2=1.28.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/bitset/18604.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/deque/18604.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/list/18604.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/map/18604.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/set/18604.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/23_containers/vector/18604.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/deque.tcc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.20&r2=1.20.34.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_bvector.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.39.6.2&r2=1.39.6.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_deque.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.56&r2=1.56.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_list.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.47&r2=1.47.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_map.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.25&r2=1.25.40.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_multimap.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.24&r2=1.24.40.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_multiset.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.24&r2=1.24.44.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_set.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.23&r2=1.23.44.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_vector.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.53&r2=1.53.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/vector.tcc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.22&r2=1.22.10.1

Comment 18 Giovanni Bajo 2005-05-10 09:42:59 UTC
Thanks Paolo!