From: Rom A. <a_r...@ho...> - 2012-06-08 18:36:28
|
/* Hi folks, I've upgraded my g++ version from 3.4.5 to 4.6.2 and now code that was building just fine with 3.4.5. no longer builds with 4.6.2. In particularly, a scope resolution problem related to friend functions when the class it is a friend of is actually defined inside a namespace. This is the main case that is causing the build to fail at this point. The sample sources include below reproduce this problem quite well. Any input is welcome. Your response is greatly appreciated. ( THANK YOU ) OS : Windows XP SP3 Compiler version 4.6.2 g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe Target: mingw32 Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw Thread model: win32 gcc version 4.6.2 (GCC) To build copy the source to a file called sample.cpp then g++ -c sample.cpp sample.cpp:89:69: error: 'bool AppGlobal::operator==(const AppGlobal::TimeStamp&, const AppGlobal::TimeStamp&)' should have been declared inside 'AppGlobal' Compilation exited abnormally with code 1 at Fri Jun 08 15:10:22 */ #include <time.h> using namespace std; namespace AppGlobal // AppGlobal Namespace .... { class TimeStamp { public: // Default constructor. TimeStamp() throw(); // Destructor. ~TimeStamp() throw(); // Copy constructor. TimeStamp(const TimeStamp& rhs) throw(); // ( HERE IS WHERE THE SCOPE PROBLEM HAPPENS IN 4.6.2 but not in // 3.4.5) // Equality operator. friend bool operator==(const TimeStamp& a, const TimeStamp& b) throw(); private: static time_t ms_TimeAtReference; static time_t ms_ReferenceTime; time_t m_Time; }; // End class TimeStamp } // End namespace ( AppGlobal ) using AppGlobal::TimeStamp; using namespace AppGlobal; time_t TimeStamp::ms_TimeAtReference = 0; // Static initialization time_t TimeStamp::ms_ReferenceTime = 0; // Static initialization. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Default constructor. TimeStamp::TimeStamp() throw() : m_Time(0) { if (ms_ReferenceTime == 0) { ms_TimeAtReference = ::time(0); ms_ReferenceTime = ::time(0); } } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Destructor. TimeStamp::~TimeStamp() throw() { } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Copy constructor. TimeStamp::TimeStamp(const TimeStamp& rhs) throw() : m_Time(rhs.m_Time) { } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Equality operator. (THIS IS WHERE g++ breaks on scope resolution problems. /*Friend Function*/ bool AppGlobal::operator==(const TimeStamp& a, const TimeStamp& b) throw() { return a.m_Time == b.m_Time; } Your response is greatly appreciated. --Rom a_r...@ho... |