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]

auto_ptr ICE 20000422 with gcc version 20000530


Hi,

I get an ICE when compiling with -O.
The code compiles ok without -O.
Something goes wrong with auto_ptr.

Regards,
Peter
---------
>>uname -a
Linux peternl 2.2.12-20 #1 Wed May 24 16:03:15 CEST 2000 i686 unknown
>>gcc -v
Reading specs from
/home/petern/gcc/install/gcc/2000-05-30/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs

gcc version 2.96 20000530 (experimental)

Command line:
gcc -v --save-temps -O bug.cpp

Source below, see also attched tar-file with temp-files.
----------------
#define GCC_EXPLICIT_TEMPLATE_SELECTION_BUG
namespace ManagedSingleton {
template <typename T /* Singleton type */, typename MANAGER>
class Singleton {
public:
  typedef MANAGER ManagerType;
  typedef T       SingletonType;
  inline static T& instance();            //>x
  inline static const T& constInstance(); //>x
protected:
  Singleton()  { };                       // NOTHROW
  ~Singleton() { };                       // NOTHROW
private:
  Singleton(const Singleton&);            // Shouldn't be used
  Singleton& operator=(const Singleton&); // Shouldn't be used
};

// Singleton Adapter class. Will "convert" a class T into a Singleton.
template <typename T, typename MANAGER>
struct SingletonAdapter: public Singleton<T, MANAGER> { };

// Master template, should never be used.
// This class will manage the individual Singletons.
// A Manager class will exploit this class when managing
// all Singletons as a collection.
template <typename T, typename MANAGER>
class InstanceManager{};

/////////////////////////////////////////////////////////
// Implementations
//
template <typename T, typename MANAGER>
inline T& Singleton<T, MANAGER>::instance() {
  return MANAGER::
#ifdef GCC_EXPLICIT_TEMPLATE_SELECTION_BUG
    // Patch "template" should not be needed on line below.
    template
#endif
    instance<T>(); //>x
}

template <typename T, typename MANAGER>
inline const T& Singleton<T, MANAGER>::constInstance() { return
instance(); }

}; // namespace ManagedSingleton

//-------------------------------
#include <memory>

namespace ManagedSingleton {

  struct CleanupMgr {
    template <typename T> static T& instance() {
      return InstanceManager<T, CleanupMgr>::instance(); //>x
    }
  };

  template <typename T>
  class InstanceManager<T, CleanupMgr> {
    friend class CleanupMgr;
    static T& instance() {
      static std::auto_ptr<T> instance_(new T);  //>x
      return *instance_.get();                   // NOTHROW
    }
  };
}; // namespace ManagedSingleton
//---------------------------------
#define SIMPLE_CLEANUP_MGR

#include <iostream>
#include <exception> // For terminate

typedef ManagedSingleton::CleanupMgr Mgr;

using namespace ManagedSingleton;

class WillBecomeSingleton {
  template <typename DS, typename MGR2> friend class InstanceManager;
  friend class std::auto_ptr<WillBecomeSingleton>; // Not the best
solution, but simple ...
public:
  typedef int CountType;
  void print() const throw() { std::cerr <<
"WillBecomeSingleton.print()" << std::endl; }
  int testFunction() throw(const char*) {
    throw "Simulate failure in WillBecomeSingleton::testFunction()";
    return 1;
  }
private:
  WillBecomeSingleton() throw(const char*){
    std::cerr << "WillBecomeSingleton" << std::endl;
  }
  ~WillBecomeSingleton() throw() { std::cerr << "~WillBecomeSingleton"
<< std::endl; }
};

typedef SingletonAdapter<WillBecomeSingleton, Mgr> AdaptedSingleton;

int main(int argc, const char** argv){
  AdaptedSingleton::instance();
  return 0;
}

bug.tgz


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