'Compile Errors When Including Boost 1.79.0 Bimap w/ Unreal 5

For over a year, I was using Boost's Bimap for the basis of an inventory system.

typedef boost::bimap<boost::bimaps::set_of<uint32>,
    boost::bimaps::multiset_of<uint32>,
    boost::bimaps::with_info<FItemDetails>> InventoryBimap;

After updating from Unreal 4 to Unreal 5, though, I made a few other changes. I moved from Boost 1.68.0 to 1.79.0. I moved from C++17 to C++20.

Edit: Sorry, I forgot to include I'm using Visual Studio 2022.

There are two sources for a bunch of compilation errors that prevent my game from compiling:

1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(127): note: see reference to class template instantiation 'boost::detail::ptr_to_expr<T,E>' being compiled
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2059: syntax error: '->'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2238: unexpected token(s) preceding ';'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2334: unexpected token(s) preceding '{'; skipping apparent function body

And then:

1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(407): note: see reference to class template instantiation 'boost::detail::alloc_has_allocate<A>' being compiled
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(398): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(398): error C2059: syntax error: '->'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(400): error C2238: unexpected token(s) preceding ';'

The second error repeats for every single template inside of allocator_access.hpp.

The only short-term fix I've found so far is to comment out all of the bimap includes in my project.

I am currently unsure of how to proceed and was hoping someone had some insight into what may be going on.



Solution 1:[1]

So, I found an answer. I'll share it here so that everyone can know:

In pointer_traits.hpp, the template has two functions:

        template<class O>
        static auto check(int)->result<decltype(O::pointer_to(source()))>;

        template<class>
        static char check(long);

I suddenly noticed the name: "check".

"check" is an Unreal macro name that forces Unreal Engine to crash upon invocation (unless a debugger is attached). Therefore, the function invocation that looked normal was instead being interpreted as a call to Unreal's check macro and causing compilation failures.

So I had to rename "check" throughout boost to something else. This fixed the compile errors, and my inventory system has been working again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Posokhov