This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
namespace bug, ICE.
- To: gcc-bugs at gcc dot gnu dot org, c++support at kai dot com
- Subject: namespace bug, ICE.
- From: Peter Nordlund <peter dot nordlund at lentus dot se>
- Date: Fri, 09 Jun 2000 14:56:57 +0200
- References: <393F4A5C.A8D095@lentus.se>
This code produces an ICE on gcc 2000-06-04.
The code doesnt work on KCC 3.4 either, but with quite a different
behaviour.
See compilation commands and output att the bottom of the code.
Best regards,
Peter
//------------
#ifndef NSBUG
# define NAMESPACE_BUG //GCC gets an ICE if explicit scoping is used.
#else
# define NAMESPACE_BUG ManagedSingleton::
#endif
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
};
// Master template, should never be used.
template <typename T, typename MANAGER> class InstanceManager{};
/////////////////////////////////////////////////////////
// Implementations
//
template <typename T, typename MANAGER>
inline T& Singleton<T, MANAGER>::instance() {
T* typeArg = 0;
return MANAGER::instance(typeArg); //>x
}
template <typename T, typename MANAGER>
inline const T& Singleton<T, MANAGER>::constInstance() { return
instance(); }
}; // namespace ManagedSingleton
//##########################
namespace ManagedSingleton {
// Simple Singleton Manager with no cleanup.
// (Has bad performance under Cygwin and gcc 2.95.2.)
//
struct NoCleanupMgr2 {
template <typename T> static T& instance(T*) { //>x
return InstanceManager<T, NoCleanupMgr2>::instance();//>x
}
};
// Template specialization.
template <typename T>
class InstanceManager<T, NoCleanupMgr2> {
friend class NoCleanupMgr2;
static T& instance() { //>x
static T* instance_ = new T; //>x
return *instance_; // NOTHROW
}
};
}; // namespace ManagedSingleton
//##################################################
using namespace ManagedSingleton;
// Test class
template <int I, typename MGR>
class Test: public Singleton<Test<I, MGR>, MGR> {
template <typename DS, typename MGR2> friend class NAMESPACE_BUG
InstanceManager;
private:
Test() {};
};
typedef Test<1, NoCleanupMgr2> Test1;
int main(int argc, const char** argv){
Test1::constInstance();
return 0;
}
//##############################################
#if 0
This code produces an ICE on gcc.
The code doesnt work on KCC either, but with quite a different
behaviour.
See compilation commands and output below:
>>uname -a
Linux peternl 2.2.12-20 #1 Wed May 24 16:03:15 CEST 2000 i686 unknown
>>g++ -v
Reading specs from
/home/petern/gcc/install/gcc/2000-06-04/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
gcc version 2.96 20000604 (experimental)
// ## Gcc 2000-06-04
>>g++ bug.cpp // ###### Works ok!
>>g++ -DNSBUG bug.cpp
bug.cpp: In instantiation of Test<1, ManagedSingleton::NoCleanupMgr2>:
bug.cpp:79: instantiated from here
bug.cpp:70: Internal compiler error.
bug.cpp:70: Please submit a full bug report.
bug.cpp:70: See <URL:http://www.gnu.org/software/gcc/bugs.html> for
instructions.
// ## KCC 3.4
>>KCC -DNSBUG bug.cpp // ###### Works ok!
>>KCC bug.cpp
"bug.cpp", line 57: error: "Test<I, MGR>::Test() [with I=1,
MGR=ManagedSingleton::NoCleanupMgr2]" is inaccessible
static T* instance_ = new T; //>x
^
detected during:
instantiation of "T &ManagedSingleton::InstanceManager<T,
ManagedSingleton::NoCleanupMgr2>::instance() [with
T=Test<1, ManagedSingleton::NoCleanupMgr2>]" at
line 48
instantiation of "T
&ManagedSingleton::NoCleanupMgr2::instance(T
*) [with T=Test<1,
ManagedSingleton::NoCleanupMgr2>]" at
line 31
instantiation of "T &ManagedSingleton::Singleton<T,
MANAGER>::instance() [with T=Test<1,
ManagedSingleton::NoCleanupMgr2>,
MANAGER=ManagedSingleton::NoCleanupMgr2]" at line
35
instantiation of "const T &ManagedSingleton::Singleton<T,
MANAGER>::constInstance() [with T=Test<1,
ManagedSingleton::NoCleanupMgr2>,
MANAGER=ManagedSingleton::NoCleanupMgr2]" at line
79
1 error detected in the compilation of "bug.cpp".
KCC: Compilation failed.
#endif // #if 0