Boost logo

Boost Users :

Subject: Re: [Boost-users] Weird code in lockfree::queue::reserve (compilation error)
From: Aurelien Regat-Barrel (arb_at_[hidden])
Date: 2016-04-02 19:40:46


> What error are you getting?

VC++ 2015 emits a syntax error:

    void f() {
        boost::lockfree::queue<int*, boost::lockfree::fixed_sized<true>> queue;

    1>boost\lockfree\queue.hpp(226): error C2059: syntax error: 'template'

I figured out this is because of the "boost::lockfree::fixed_sized<true>" option. If I removed it, it compiles fine. So I managed to set the size of my queue at construction time.

Do you think it would be possible to improve the error message?

=== Bonus! ===

I was using VC++ 2015 Update 1, and I just updated to Update 2... and I get another error from std::atomic:

        static_assert(alignof(_Ty) >= alignof(_My_int),
                "You've instantiated std::atomic<T> with sizeof(T) equal to 2/4/8 and alignof(T) < sizeof(T). "
                "Before VS 2015 Update 2, this would have misbehaved at runtime. "
                "VS 2015 Update 2 was fixed to handle this correctly, "
                "but the fix inherently changes layout and breaks binary compatibility. "
                "Please define _ENABLE_ATOMIC_ALIGNMENT_FIX to acknowledge that you understand this, "
                "and that everything you're linking has been compiled with VS 2015 Update 2 (or later).");

This is caused by the following code in boost\lockfree\detail\freelist.hpp(603):
    std::atomic<boost::lockfree::detail::tagged_index> pool_;

with sizeof(tagged_index) == 4 and alignof(tagged_index) == 2.

It can be fixed by changing tagged_index to be alignas(4), or by defining _ENABLE_ATOMIC_ALIGNMENT_FIX:

    #if _MSC_FULL_VER == 190023918 // VC++ 2015 Update 2

Since there's a compiler bug prior to Update 2 (, may be the source should be updated to not compile if the code generated by VC++ is not reliable?


Aurélien Regat-Barrel

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at