Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuple_size_v fails with optional<unique_ptr<...>> field in the structure #110

Open
dragon-dreamer opened this issue Nov 30, 2022 · 0 comments

Comments

@dragon-dreamer
Copy link

This code fails to compile with both clang and gcc trunk (but compiles with the latest MSVC):

#include <memory>
#include <optional>

#include <boost/pfr/core.hpp>

struct optional_linked_list
{
	int value;
	std::optional<std::unique_ptr<optional_linked_list>> next;
};

int main()
{
    return boost::pfr::tuple_size_v<optional_linked_list>;
}

Also see https://godbolt.org/z/1d9W5e4b3 (tested with Boost 1.80.0).

This is the clang-trunk compile error:

In file included from <source>:4:
In file included from /opt/compiler-explorer/libs/boost_1_80_0/boost/pfr/core.hpp:12:
In file included from /opt/compiler-explorer/libs/boost_1_80_0/boost/pfr/detail/core.hpp:17:
In file included from /opt/compiler-explorer/libs/boost_1_80_0/boost/pfr/detail/core17.hpp:11:
In file included from /opt/compiler-explorer/libs/boost_1_80_0/boost/pfr/detail/fields_count.hpp:13:
/opt/compiler-explorer/libs/boost_1_80_0/boost/pfr/detail/unsafe_declval.hpp:29:12: error: static_cast from 'typename std::remove_reference<unique_ptr<optional_linked_list>>::type' (aka 'std::unique_ptr<optional_linked_list>') to 'std::unique_ptr<optional_linked_list>' uses deleted function
    return static_cast<T>(*ptr);
           ^~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/boost_1_80_0/boost/pfr/detail/fields_count.hpp:45:24: note: in instantiation of function template specialization 'boost::pfr::detail::unsafe_declval<std::unique_ptr<optional_linked_list>>' requested here
        return detail::unsafe_declval<Type>();
                       ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/optional:244:17: note: in instantiation of function template specialization 'boost::pfr::detail::ubiq_rref_constructor::operator unique_ptr<std::unique_ptr<optional_linked_list>>' requested here
            : _M_value(std::forward<_Args>(__args)...)
                       ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/bits/unique_ptr.h:523:7: note: candidate constructor has been explicitly deleted
      unique_ptr(const unique_ptr&) = delete;
      ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant