boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
100 stars 116 forks source link

MSVC + boost 1.70 compilation error when windows.h is already included (detail/thread_mutex.hpp) #116

Closed mrpi closed 5 years ago

mrpi commented 5 years ago

There is an ADL problem with boost 1.70.0 that did not occur for us with 1.67.0.

When _BOOST_USE_WINDOWSH is not defined but windows.h has already been included, the calls to InitializeCriticalSection(Ex), EnterCriticalSection, LeaveCriticalSection and DeleteCriticalSection are ambiguous.

I have pasted the problematic part on godbold where you can see the bug: Godbolt of bug If you uncomment the line //#define WORKAROUND a simple fix is applied.

file with error: detail/thread_mutex.hpp

error C2668: 'boost::container::dtl::InitializeCriticalSection': ambiguous call to overloaded function note: could be 'void boost::container::dtl::InitializeCriticalSection(_RTL_CRITICAL_SECTION )' C:/WinSdk/Include/10.0.17763.0/um\synchapi.h(123): note: or 'void InitializeCriticalSection(LPCRITICAL_SECTION)' [found using argument-dependent lookup] note: while trying to match the argument list '(_RTL_CRITICAL_SECTION )'

error C2668: 'boost::container::dtl::EnterCriticalSection': ambiguous call to overloaded function note: could be 'void boost::container::dtl::EnterCriticalSection(_RTL_CRITICAL_SECTION )' C:/WinSdk/Include/10.0.17763.0/um\synchapi.h(133): note: or 'void EnterCriticalSection(LPCRITICAL_SECTION)' [found using argument-dependent lookup] note: while trying to match the argument list '(_RTL_CRITICAL_SECTION )'

error C2668: 'boost::container::dtl::LeaveCriticalSection': ambiguous call to overloaded function note: could be 'void boost::container::dtl::LeaveCriticalSection(_RTL_CRITICAL_SECTION )' C:/WinSdk/Include/10.0.17763.0/um\synchapi.h(141): note: or 'void LeaveCriticalSection(LPCRITICAL_SECTION)' [found using argument-dependent lookup] note: while trying to match the argument list '(_RTL_CRITICAL_SECTION )'

error C2668: 'boost::container::dtl::DeleteCriticalSection': ambiguous call to overloaded function note: could be 'void boost::container::dtl::DeleteCriticalSection(_RTL_CRITICAL_SECTION )' C:/WinSdk/Include/10.0.17763.0/um\synchapi.h(194): note: or 'void DeleteCriticalSection(LPCRITICAL_SECTION)' [found using argument-dependent lookup] note: while trying to match the argument list '(_RTL_CRITICAL_SECTION )'

igaztanaga commented 5 years ago

Thanks for the report!