GCC 3.2 compiler error using Boost::Threads::Mutex::scoped_lock
Disclaimer: I am relatively new to gcc, linux and Boost. I'm hoping someone out in the group who is much more knowledgable about all of them can help me get past a hurdle in code I am porting from Windows. I am getting a vague error message from g++ (gcc 3.2-7 under Redhat Linux 8.0) in my code using the Boost scoped_lock. I have wrapped the Boost versions of mutex and mutex::scoped_lock as: class PMutex { public: PMutex() {} virtual ~PMutex() {} protected: boost::mutex m_Mutex; friend class PScopedLock; }; class PScopedLock { public: explicit PScopedLock( PMutex& M ) : m_ScopedLock(M.m_Mutex) {} virtual ~PScopedLock() {} static PScopedLock* Create( PMutex& M ) { return (PScopedLock*) ::new PScopedLock(M); } void Destroy( void ) { delete this; } protected: void* operator new(size_t) {} // disallowed, must declare on the stack boost::mutex::scoped_lock m_ScopedLock; friend class PCondition; }; The error is "ISO C++ forbids declarations of 'type name' with no type". I get that error on several lines, but most notably on a simple declaration like: PScopedLock Lock(MyMutex); From what little I can find on the newsgroups, this sort of error has been noted when use of template template parameters are not declared quite correctly (without the trailing ::template from what I can gather). But as far as I can tell, I should not be having that issue. I am not knowledgeable enough about templates, Boost or gcc/g++ to sort out what I am running into. Boost builds fine under gcc, the code I am porting compiles fine under MSVC6 and Kylix3, but not gcc. Can anyone help me out? thanks. michael
Michael Hunley wrote:
Disclaimer: I am relatively new to gcc, linux and Boost. I'm hoping someone out in the group who is much more knowledgable about all of them can help me get past a hurdle in code I am porting from Windows. I am getting a vague error message from g++ (gcc 3.2-7 under Redhat Linux 8.0) in my code using the Boost scoped_lock.
[ snip ]
The error is "ISO C++ forbids declarations of 'type name' with no
type". I
get that error on several lines, but most notably on a simple declaration like: PScopedLock Lock(MyMutex);
Hi Michael, I think you will need to post some more code; I have tried the code you posted, including your simple declaration, on the same platform (gcc 3.2-7 under Redhat Linux 8.0) - with boost 1.29.0. This compiles without error. (See below.) Regards, Stephen Jackson -- stephen.jackson@scribitur.com http://www.scribitur.com/spj/ gcc -c -Iboost_1_29_0 testit.cpp -Wall #include "boost/thread/mutex.hpp" // Begin your posted code class PMutex { public: PMutex() {} virtual ~PMutex() {} protected: boost::mutex m_Mutex; friend class PScopedLock; }; class PScopedLock { public: explicit PScopedLock( PMutex& M ) : m_ScopedLock(M.m_Mutex) {} virtual ~PScopedLock() {} static PScopedLock* Create( PMutex& M ) { return (PScopedLock*) ::new PScopedLock(M); } void Destroy( void ) { delete this; } protected: void* operator new(size_t) {} /* disallowed, must declare on the stack */ boost::mutex::scoped_lock m_ScopedLock; friend class PCondition; }; // End your posted code void this_is_a_test() { PMutex MyMutex; PScopedLock Lock(MyMutex); // Compiles OK }
At 11:44 PM 3/4/2003 +0000, you wrote:
I think you will need to post some more code; I have tried the code you posted, including your simple declaration, on the same platform (gcc 3.2-7 under Redhat Linux 8.0) - with boost 1.29.0. This compiles without error. (See below.)
thanks for taking the time. Unfortunately (for my pride), I found the error and should have spotted it before I posted. As you gathered from your test, it had nothing to do with the PScopedLock. It just so happened that I put the same quick test hack to get something working along side a lot of those declarations. The hack involved "casting" a variable to volatile so it didn't get optimized away (in lieu of real synchronization on a shared data value). Of course it worked fine in the quite forgiving MSDev environ, but GCC complained about the cast. Sorry for the faulty post. michael
participants (2)
-
Michael Hunley
-
Stephen Jackson