Curious issue with char_traits
Paolo Carlini
pcarlini@suse.de
Tue Oct 25 13:16:00 GMT 2005
Hi,
while answering privately a message from a user, I noticed a curious
glitch. Consider this:
--------
#include <string>
using namespace __gnu_cxx;
using namespace std;
typedef basic_string<char, char_traits<char>, allocator<char> > mystr;
--------
Well, doesn't compile!
plain.cc:6: error: 'char_traits' was not declared in this scope
plain.cc:6: error: missing '>' to terminate the template argument list
plain.cc:6: error: template argument 2 is invalid
plain.cc:6: error: expected unqualified-id before '>' token
The problem is that our "extended" char_traits implementation involves a
template struct named char_traits *both* in __gnu_cxx and in std (which
uses the former). But __gnu_cxx is the namespace where all our extension
facilities live and as soon as a user does 'using namespace __gnu_cxx;'
(I think it can be common), then char_traits becomes ambiguous (an
additional std:: qualifier becomes necessary)
I think we should fix this, i.e., we should render std::char_traits
robust wrt using-directives. What about renaming __gnu_cxx::char_traits
to something like __gnu_cxx::__char_traits? This would fix the problem
at issue and it would still be possible to specialize
__gnu_cxx::__char_traits.
Opinions?
Paolo.
More information about the Libstdc++
mailing list