This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: STL in global or std namespace?




On Wed, 24 Nov 1999, John Law wrote:

> Hi,
> 
> I'm currently using GCC 2.95.2 on my Linux box and have been getting
> compilation
> problems because one of my header file contains:
> 
> // header combined for c and c++
> 
> #ifdef __cplusplus
> namespace Trans
> {
> #endif
> 
> typedef	char	unique[14];
> 
> #ifdef __cplusplus
> }
> 
> using namespace Trans;
> 
> #endif
> 
> typedef struct
> {
>   unique transaction_id;
> } TEMPLATE;
> 
> 
> I have found that whenever compiling a c++ application that includes this
> header file I get "use of `unique' is ambiguous"
> 
> <path to header>/stl_algo.h:652:   first declared as `_ForwardIter
> unique(_ForwardIter, _ForwardIter, _BinaryPredicate)' here
> /src/include/TransTemplate.h:42:    also declared as `typedef char
> Nmac::unique[14]' here
> 
> The surprising thing about this is that although it is considered bad
> practice to
> include the 'using namespace Trans' in a header file, this was I thought, a
> simple
> solution to a larger problem in that I didn't fancy having to rename each
> unique
> entry in all the source files that use 'unique' (which is over 750
> files...). So
> I simply include it within a namespace if compiling using c++. The errors
> surprised
> me in that I hadn't included 'using namespace std' so wasn't expecting to
> get any
> conflicts with STL's unique.
> 
> I suppose my question is if using libstdc++-2.90.6 is the STL included in
> the global
> namespace, or in the std namespace. It kind of looks like its still in the
> global
> namespace. If so, anyone got any ideas of when it will be in the std
> namespace?
> or anyone got any other simple soloutions to this problem?
> 
> 
> Cheers
> 
> John
> 

gcc contains a hack that ignores the std:: namespace; anything in
  the std namespace is also simultaneously in the global namespace.
  E.g. , gcc is happy to accept 'using std::vector;' but you can still use
  vector whether or not you have an appropriate using decl.

IIRC, the hack is entirely in gcc, and libstdc++ hasn't got anything to
  say about it.

If you want namespace std to be honored, compile with -fhonor-std ... but
  since namespaces get mangled into signatures, I bet you will need to
  re-compile libstdc++ with -fhonor-std.

However, I can't recall having used -fhonor-std recently ... anyone else
  used it?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]