Skip to content

Commit

Permalink
Merge pull request #140 from denzor200/get_name_fixes
Browse files Browse the repository at this point in the history
Couple of fixes for get_name
  • Loading branch information
apolukhin committed Sep 23, 2023
2 parents 730f40b + 53fcd78 commit 7e19e45
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/boost/pfr/detail/core_name20_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ constexpr std::string_view get_name() noexcept {
!std::is_union<T>::value,
"====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
);
static_assert(
!std::is_array<T>::value,
"====================> Boost.PFR: It is impossible to extract name from old C array since it doesn't have named members"
);
static_assert(
sizeof(T) && BOOST_PFR_USE_CPP17,
"====================> Boost.PFR: Extraction of field's names is allowed only when the BOOST_PFR_USE_CPP17 macro enabled."
Expand All @@ -220,6 +224,10 @@ constexpr auto tie_as_names_tuple() noexcept {
!std::is_union<T>::value,
"====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
);
static_assert(
!std::is_array<T>::value,
"====================> Boost.PFR: It is impossible to extract name from old C array since it doesn't have named members"
);
static_assert(
sizeof(T) && BOOST_PFR_USE_CPP17,
"====================> Boost.PFR: Extraction of field's names is allowed only when the BOOST_PFR_USE_CPP17 macro enabled."
Expand Down
5 changes: 4 additions & 1 deletion test/config/print_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/pfr/config.hpp> // inclusion of an another PFR header may fail when BOOST_PFR_ENABLED=0
#include <boost/pfr/config.hpp>
#if BOOST_PFR_ENABLED
#include <boost/pfr.hpp>
#endif
#include <boost/preprocessor/stringize.hpp>

#include <iostream>
Expand Down
17 changes: 17 additions & 0 deletions test/core_name/compile-fail/fields_names_get_name_on_array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)


// Initial implementation by Bela Schaum, https://github.com/schaumb
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
//

#include <boost/pfr/core_name.hpp>

int main() {
(void)boost::pfr::get_name<0, int[10]>(); // Must be a compile time error
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)


// Initial implementation by Bela Schaum, https://github.com/schaumb
// The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
//

#include <boost/pfr/core_name.hpp>

int main() {
(void)boost::pfr::names_as_array<int[10]>(); // Must be a compile time error
}


0 comments on commit 7e19e45

Please sign in to comment.