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

MSVC 14.1 warning: unreferenced parameter in stdtuple.hpp #167

Closed anarthal closed 7 months ago

anarthal commented 8 months ago

Compiler: MSVC 14.1 (Visual Studio 2017) The full build log is here: https://drone.cpp.al/boostorg/mysql/621/31/2

The following warning is emitted:

.\boost/pfr/detail/stdtuple.hpp(20): error C2220: warning treated as error - no 'object' file generated
.\boost/pfr/detail/stdtuple.hpp(20): warning C4100: 't': unreferenced formal parameter
.\boost/pfr/core.hpp(147): note: see reference to function template instantiation 'std::tuple<> boost::pfr::detail::make_stdtuple_from_tietuple<boost::pfr::detail::sequence_tuple::tuple<>,>(const T &,std::integer_sequence<unsigned int>)' being compiled
        with
        [
            T=boost::pfr::detail::sequence_tuple::tuple<>
        ]

When using pfr::structure_to_tuple with an empty struct. This is caused by the following code in detail/stdtuple.hpp:

template <class T, std::size_t... I>
constexpr auto make_stdtuple_from_tietuple(const T& t, std::index_sequence<I...>) {
    return std::make_tuple(
        boost::pfr::detail::sequence_tuple::get<I>(t)...
    );
}

This is actually a bug in MSVC 14.1. It will emit the warning if t is an empty tuple. It can be silenced by sticking a boost::ignore_unused(t).

apolukhin commented 7 months ago

Many thanks! Fixed