mirror of
https://github.com/boostorg/pfr.git
synced 2026-01-19 04:22:13 +00:00
Harden the filed name checks and improve the diagnostics (#138)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
//
|
||||
|
||||
#define BOOST_PFR_FUNCTION_SIGNATURE "dummy"
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (3,2,false,"")
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (3,2,"")
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
|
||||
struct A { int field; };
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
|
||||
#define BOOST_PFR_FUNCTION_SIGNATURE " *[field] "
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (3,2,false,"")
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (3,2,"")
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
@@ -17,7 +17,7 @@
|
||||
struct A { int field; };
|
||||
|
||||
int main() {
|
||||
BOOST_TEST_EQ( ((boost::pfr::get_name<0,A>())), "field");
|
||||
BOOST_TEST_EQ( (boost::pfr::get_name<0,A>()), "field");
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -13,19 +13,30 @@
|
||||
// This cpp file:
|
||||
// * tests BOOST_PFR_CORE_NAME_PARSING macro
|
||||
// * outputs full name of the function so that PFRs extraction of field name could be adjust to new compiler without requesting regression tester's help
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (0,0,false,"")
|
||||
#ifndef BOOST_PFR_CORE_NAME_PARSING
|
||||
#define BOOST_PFR_CORE_NAME_PARSING (0,0,"")
|
||||
#endif
|
||||
|
||||
#include <boost/pfr/core_name.hpp>
|
||||
|
||||
namespace user_defined_namespace {
|
||||
struct user_defined_class { int user_defined_field; };
|
||||
}
|
||||
|
||||
using namespace boost::pfr;
|
||||
|
||||
// Cloned from core_name20_static.hpp but removed the sanity check
|
||||
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>)
|
||||
)))
|
||||
>();
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::pfr;
|
||||
|
||||
std::cout << "user_defined_namespace::user_defined_class::user_defined_field: "
|
||||
<< get_name<0, user_defined_namespace::user_defined_class>() << '\n';
|
||||
<< no_check_stored_name_of_field<user_defined_namespace::user_defined_class, 0>.data() << '\n';
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace testing
|
||||
{
|
||||
namespace testing {
|
||||
|
||||
constexpr std::string_view fake_func_name = " ******************** [fake_text1->fake_text2->fake_text3] **********";
|
||||
|
||||
@@ -22,35 +21,25 @@ void test_general()
|
||||
{
|
||||
namespace detail = boost::pfr::detail;
|
||||
using detail::backward;
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, false, "").apply(fake_func_name), "fake_text1->fake_text2->fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "").apply(fake_func_name), "fake_text1->fake_text2->fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, backward("->")).apply(fake_func_name), "fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "->").apply(fake_func_name), "fake_text2->fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, backward("->")).apply(fake_func_name), "fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, "->").apply(fake_func_name), "fake_text2->fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, true, backward("->")).apply(fake_func_name), "fake_text3");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(23, 12, true, "->").apply(fake_func_name), "fake_text2->fake_text3");
|
||||
}
|
||||
|
||||
void test_undefided_parser()
|
||||
{
|
||||
namespace detail = boost::pfr::detail;
|
||||
using detail::backward;
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, backward("")).apply(fake_func_name), "");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, "").apply(fake_func_name), "");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, true, backward("")).apply(fake_func_name), "");
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, true, "").apply(fake_func_name), "");
|
||||
}
|
||||
|
||||
void test_identity_parser()
|
||||
{
|
||||
namespace detail = boost::pfr::detail;
|
||||
using detail::backward;
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, false, backward("")).apply(fake_func_name), fake_func_name);
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, false, "").apply(fake_func_name), fake_func_name);
|
||||
}
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, backward("")).apply(fake_func_name), fake_func_name);
|
||||
BOOST_TEST_EQ(detail::make_core_name_skip(0, 0, "").apply(fake_func_name), fake_func_name);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
int main() {
|
||||
testing::test_general();
|
||||
testing::test_undefided_parser();
|
||||
testing::test_identity_parser();
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
Reference in New Issue
Block a user