This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A specialization bug?


You are right that wrapping the specialization in std is required by
the standard:

"It is undefined for a C++ program to add declarations or definitions
to namespace std or namespaces within namespace std unless otherwise
specified. A program may add template specializations for any
standard
library template to namespace std. Such a specialization (complete or
partial) of a standard library template results on undefined behavior
unless the declaration depends on a user-defined name of external
linkage and unless the specialization meets the standard library
requirements for the original template."

However, the behaviour as shown by gcc 2.95.3 is not
standard-compliant, according to
http://www.csci.csusb.edu/dick/c++std/cd2/template.html:

-------------------------------------------------------------------
A template explicit specialization is in the scope of the namespace
in
which the template was defined.  [Example:

  namespace N {
    template<class T> class X { /* ... */ };
    template<class T> class Y { /* ... */ };

    template<> class X<int> { /* ... */ }; // ok: specialization
                                           //     in same namespace
    template<> class Y<double>;            // forward declare intent
to
                                           // specialize for double
  }

  template<> class N::Y<double> { /* ... */ }; // ok: specialization
                                               //     in same
namespace
--end example]
-------------------------------------------------------------------

So my code should be legal and it seems a bug of gcc 2.95.3. And in
this case Borland C++ and Visual C++ are more standards-compliant.

How do you think? Does gcc 3.0 have this problem? Could a later
release of gcc 2.x solve it? Or still I err somehwhere?

Best regards,

Wu Yongwei

--- Original Message from Phil Edwards ---

> Gcc 2.95.3 in default configuration compiles it well.

GCC 2.x did not fully support namespace std.  GCC 3 does.  Code which
assumes the existence or non-existence of std:: will often behave
differently when moving from 2.x to 3.x.

> I have to wrap the definition in namespace std to make it compile,
> which seems against the C++ standard.

It's required by the standard.  If you are going to specialize a
template declared in namespace std, then you must re-open namespace
std to write the specialization.  Writing std::hash isn't enough.

Note that hash_map and the hash template are /not/ part of the C++
standard. They're sitting in namespace std in GCC 3.0 for hysterical
raisins. For a future GCC release they will be in a different
namespace.


Phil


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