This is the mail archive of the libstdc++@gcc.gnu.org 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]
Other format: [Raw text]

Re: EEEEKS! The mangling changed!


On Wed, Dec 03, 2003 at 05:06:29AM +0100, Carlo Wood wrote:
> When, in debug mode, specializations defined by the user in namespace std
> are mangled as "St", then "St" corresponds to debug mode and it would not
> be possible to define a specialization for normal containers in debug mode
> when normal containers go into "St" as well.

Tiny little problem...  They DON'T go into "St".

Consider the following test code:


#include <vector>
#include <iostream>

struct MyType { };

namespace std {
  template<>
    struct vector<MyType>
    {
      vector() { std::cout << "Calling specialization in std::\n"; }
    };
}

#if 0
// It is not possible to make a specialization when _GLIBCXX_DEBUG is not defined
// because of the error: "error: expected unqualified-id"
// because there is no template vector<> in namespace __gnu_debug defined at all.
//
// It is also not possible to make a specialization when _GLIBCXX_DEBUG is defined
// because of the error: "redefinition of `struct __gnu_debug_def::vector<MyType, std::allocator<MyType> >'"
// because the specialization above in std:: collides with the one below in that case.

namespace __gnu_debug {
  template<>
    struct vector<MyType>
    {
      vector() { std::cout << "Calling specialization in __gnu_debug::\n"; }
    };
}
#endif

#ifdef _GLIBCXX_DEBUG
// It is not possible to make a specialization when _GLIBCXX_DEBUG is not defined
// because of the error: "redefinition of `struct __gnu_norm::vector<MyType, std::allocator<MyType> >'"
// because the specialization above in std:: collides with the one below in that case.
namespace __gnu_norm {
  template<>
    struct vector<MyType>
    {
      vector() { std::cout << "Calling specialization in __gnu_norm::\n"; }
    };
}
#endif

int main()
{
  std::vector<int> v1;
  std::cout << "Creating specialized std::vector<>:\n";
  std::vector<MyType> v2;		// Use normal or debug vector, depending on _GLIBCXX_DEBUG
  std::cout << "Creating specialized __gnu_norm::vector<>:\n";
  __gnu_norm::vector<MyType> v3;	// Use normal vector.
#ifdef _GLIBCXX_DEBUG	// __gnu_debug::vector only exists when this is defined.
  std::cout << "Creating specialized __gnu_debug::vector<>:\n";
  __gnu_debug::vector<MyType> v4;	// Use debug vector.
#endif
}


In debug mode:

# g++-cvs-3.4 -D_GLIBCXX_DEBUG test.cc

the specialization defined in namespace "std::" did go here:

08048846 W __gnu_debug_def::vector<MyType, std::allocator<MyType> >::vector()

in __gnu_debug_def.


Therefore the argument is void, and I have to plead again to
use "St" as mangling for __gnu_norm.

-- 
Carlo Wood <carlo@alinoe.com>


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