2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-22 17:32:35 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Denis Mikhailov
98789f610a Fix get_name on clang for MSVC (#149) 2023-11-29 09:32:30 +03:00
Denis Mikhailov
c695aa0b32 Improve diagnostic for attempt to use get_name with non-external (#146)
Co-authored-by: Antony Polukhin <antoshkka@gmail.com>
2023-11-26 11:52:17 +03:00
6 changed files with 22 additions and 5 deletions

View File

@@ -145,6 +145,10 @@ jobs:
addrmd: 64
os: windows-2022
threads: "-j1"
- toolset: clang-win
cxxstd: "14,17,2a,latest"
addrmd: 32,64
os: windows-2022
runs-on: ${{matrix.os}}

View File

@@ -109,6 +109,8 @@ void test_examples() {
// Disabled from testing since it's unportable
#if 0
{
// Keep in mind that it's unportable code
// You should move this structure somewhere outside of function scope
//[pfr_quick_examples_get_name
// Get name of field by index

View File

@@ -113,7 +113,7 @@
#ifndef BOOST_PFR_CORE_NAME_PARSING
# if defined(_MSC_VER)
# if defined(_MSC_VER) && !defined(__clang__)
# define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto __cdecl boost::pfr::detail::name_of_field_impl<") - 1, sizeof(">(void) noexcept") - 1, backward("->"))
# elif defined(__clang__)
# define BOOST_PFR_CORE_NAME_PARSING (sizeof("auto boost::pfr::detail::name_of_field_impl() [MsvcWorkaround = ") - 1, sizeof("}]") - 1, backward("."))

View File

@@ -167,7 +167,7 @@ consteval auto name_of_field() noexcept {
&& std::string_view{
detail::name_of_field_impl<
core_name_skip, detail::make_clang_wrapper(std::addressof(
fake_object<core_name_skip>.size_at_begin
detail::fake_object<core_name_skip>().size_at_begin
))
>().data()
} == "size_at_begin",
@@ -187,7 +187,7 @@ consteval auto name_of_field() noexcept {
template <class T, std::size_t I>
inline constexpr auto stored_name_of_field = detail::name_of_field<T,
detail::make_clang_wrapper(std::addressof(detail::sequence_tuple::get<I>(
detail::tie_as_tuple(detail::fake_object<T>)
detail::tie_as_tuple(detail::fake_object<T>())
)))
>();

View File

@@ -16,8 +16,19 @@
namespace boost { namespace pfr { namespace detail {
// This variable serves as a compile-time assert. If you see any error here, then
// you're probably using `boost::pfr::get_name()` or `boost::pfr::names_as_array()` with a non-external linkage type.
template <class T>
extern const T fake_object;
extern const T passed_type_has_no_external_linkage;
// For returning non default constructible types, it's exclusively used in member name retrieval.
//
// Neither std::declval nor boost::pfr::detail::unsafe_declval are usable there.
// Limitation - T should have external linkage.
template <class T>
constexpr const T& fake_object() noexcept {
return passed_type_has_no_external_linkage<T>;
}
}}} // namespace boost::pfr::detail

View File

@@ -29,7 +29,7 @@ using namespace boost::pfr;
template <class T, std::size_t I>
inline constexpr auto no_check_stored_name_of_field = detail::name_of_field_impl<T,
detail::make_clang_wrapper(std::addressof(detail::sequence_tuple::get<I>(
detail::tie_as_tuple(detail::fake_object<T>)
detail::tie_as_tuple(detail::fake_object<T>())
)))
>();