boostorg / pfr

std::tuple like methods for user defined types without any macro or boilerplate code
https://boost.org/libs/pfr
Boost Software License 1.0
1.34k stars 161 forks source link

Wrong BOOST_PFR_CORE_NAME_PARSING with "clang for MSVC" #148

Closed bansan85 closed 11 months ago

bansan85 commented 12 months ago

Under Windows with Visual Studio Installer, install "clang compiler for Windows"

With CMake, generate a project with toolset "ClangCL" : -G"Visual Studio 2022" -T ClangCL.

Build.

In this case, _MSC_VER is defined but I need to use the BOOST_PFR_CORE_NAME_PARSING from __clang__.

https://stackoverflow.com/questions/67599384/distinguish-between-clang-cl-and-msvc-cl

Solution is to check __clang__ first :

#ifndef BOOST_PFR_CORE_NAME_PARSING
#   if defined(__clang__)
#       define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto boost::pfr::detail::name_of_field_impl() [MsvcWorkaround = ") - 1, sizeof("}]") - 1, backward("."))
#   elif defined(_MSC_VER)
#       define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto __cdecl boost::pfr::detail::name_of_field_impl<") - 1, sizeof(">(void) noexcept") - 1, backward("->"))
#   elif defined(__GNUC__)
#       define BOOST_PFR_CORE_NAME_PARSING (sizeof("consteval auto boost::pfr::detail::name_of_field_impl() [with MsvcWorkaround = ") - 1, sizeof(")]") - 1, backward("::"))
#   else
// Default parser for other platforms... Just skip nothing!
#       define BOOST_PFR_CORE_NAME_PARSING (0, 0, "")
#   endif
#endif
denzor200 commented 12 months ago

Here is the fix: https://github.com/boostorg/pfr/pull/149

bansan85 commented 11 months ago

Close since fix works. Thanks.