cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.82k stars 1.68k forks source link

Won't compile in GCC 4.9.1 #8

Closed ptsneves closed 9 years ago

ptsneves commented 9 years ago

I have had this issue just including your header and compiling with GCC 4.9.1. My error log comes out like this:

concurrentqueue/concurrentqueue.h: In destructor ‘moodycamel::ConcurrentQueue<T, Traits>::ExplicitProducer::~ExplicitProducer()’:
concurrentqueue/concurrentqueue.h:1538:51: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::is_empty’
  if (block->template is_empty<explicit_context>()) {
                                               ^
concurrentqueue/concurrentqueue.h:1538:51: error:   expected a type, got ‘explicit_context’
concurrentqueue/concurrentqueue.h: In member function ‘bool moodycamel::ConcurrentQueue<T, Traits>::ExplicitProducer::enqueue(U&&)’:
concurrentqueue/concurrentqueue.h:1586:96: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::is_empty’
 if (this->tailBlock != nullptr && this->tailBlock->next->template is_empty<explicit_context>()) {
                                                                                        ^
concurrentqueue/concurrentqueue.h:1586:96: error:   expected a type, got ‘explicit_context’
concurrentqueue/concurrentqueue.h: In member function ‘bool moodycamel::ConcurrentQueue<T, Traits>::ExplicitProducer::enqueue_bulk(It, moodycamel::ConcurrentQueue<T, Traits>::size_t)’:
concurrentqueue/concurrentqueue.h:1791:168: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::is_empty’
 while (blockBaseDiff > 0 && this->tailBlock != nullptr && this->tailBlock->next != firstAllocatedBlock && this->tailBlock->next->template is_empty<explicit_context>()) {
                                                                                                                                                                    ^
concurrentqueue/concurrentqueue.h:1791:168: error:   expected a type, got ‘explicit_context’
concurrentqueue/concurrentqueue.h: In destructor ‘moodycamel::ConcurrentQueue<T, Traits>::ExplicitProducer::~ExplicitProducer()’:
concurrentqueue/concurrentqueue.h:1538:51: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::is_empty’
  if (block->template is_empty<explicit_context>()) {
                                               ^
concurrentqueue/concurrentqueue.h:1538:51: error:   expected a type, got ‘explicit_context’
concurrentqueue/concurrentqueue.h: In member function ‘bool moodycamel::ConcurrentQueue<T, Traits>::ExplicitProducer::enqueue(U&&)’:
concurrentqueue/concurrentqueue.h:1586:96: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::is_empty’
 if (this->tailBlock != nullptr && this->tailBlock->next->template is_empty<explicit_context>()) {
                                                                                            ^
concurrentqueue/concurrentqueue.h:1586:96: error:   expected a type, got ‘explicit_context’
concurrentqueue/concurrentqueue.h: In member function ‘bool moodycamel::ConcurrentQueue<T, Traits>::ExplicitProducer::enqueue_bulk(It, moodycamel::ConcurrentQueue<T, Traits>::size_t)’:
concurrentqueue/concurrentqueue.h:1791:168: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::is_empty’
 while (blockBaseDiff > 0 && this->tailBlock != nullptr && this->tailBlock->next != firstAllocatedBlock && this->tailBlock->next->template is_empty<explicit_context>()) {
                                                                                                                                                                    ^

Funny enough somebody has already tried to fix it just 3 days ago [gituhub]https://github.com/GATB/bcalm/commit/be7bda8a1553c994101ecb3f17a7d28807b9edcc so you might have a look at it.

Thanks for your work.

cameron314 commented 9 years ago

Ahh! That's... not good. It thinks my Block::is_empty() is std::is_empty. I'll have to think about how I can force the correct interpretation... this doesn't happen with g++ 4.8.1. I'd rather not resort to the linked commit's workaround (which duplicates the function definition) since I have quite a bit of repetitive code already.

Thanks for opening this issue!

cameron314 commented 9 years ago

You wouldn't happen to have a using namespace std; somewhere before the #include, would you? (It still shouldn't generate an error, mind, but it would at least make slightly more sense.)

cameron314 commented 9 years ago

I've reduced the problem to this test case: http://stackoverflow.com/q/27930448/21475 Very weird.

ptsneves commented 9 years ago

Sorry for the long delay, but I had some interruptions and I had to clean out my code of using namespace std; which I didn't even know was in a header I was including.

Your tip, was right. When I removed the using namespace std; no compile errors appeared. Thank you for avoiding a patch into a code I didn't really understand nor wanted to :D

cameron314 commented 9 years ago

Great, I'm glad you're no longer blocked by this. It's looking more and more like a bug with g++. Fortunately, there's a simple workaround, which I'll try to commit soon.

ptsneves commented 9 years ago

But with your code I was using namespace moodycamel in a cpp.

cameron314 commented 9 years ago

That should be fine. Even combined with using namespace std, there shouldn't be clashes between names (unless the standard someday adds a class called ConcurrentQueue). It's either the compiler or my code (I don't think so, but we'll see) that's the problem.

cameron314 commented 9 years ago

It's looking less like a bug in g++ (EDG generates an error too, but not Clang or VS), but definitely weird nonetheless. I've committed a fix.