1 // Copyright (c) 2020-2021 Antony Polukhin 2 // 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 7 #include <boost/pfr/core.hpp> 8 9 #include <boost/type_index.hpp> 10 11 #include <boost/core/lightweight_test.hpp> 12 13 namespace testing { 14 15 namespace { 16 17 struct other_anon { 18 int data; 19 }; 20 21 struct anon { 22 other_anon a; 23 const other_anon b; 24 }; 25 test_get_in_anon_ns_const_field()26void test_get_in_anon_ns_const_field() { 27 anon x{{1}, {2}}; 28 29 BOOST_TEST_EQ(boost::pfr::get<0>(x).data, 1); 30 auto x0_type = boost::typeindex::type_id_with_cvr<decltype( 31 boost::pfr::get<0>(x) 32 )>(); 33 // Use runtime check to make sure that Loophole fails to compile structure_tie 34 BOOST_TEST_EQ(x0_type, boost::typeindex::type_id_with_cvr<other_anon&>()); 35 36 BOOST_TEST_EQ(boost::pfr::get<1>(x).data, 2); 37 auto x1_type = boost::typeindex::type_id_with_cvr<decltype( 38 boost::pfr::get<1>(x) 39 )>(); 40 // Use runtime check to make sure that Loophole fails to compile structure_tie 41 BOOST_TEST_EQ(x1_type, boost::typeindex::type_id_with_cvr<const other_anon&>()); 42 } 43 44 } // anonymous namespace 45 46 47 } // namespace testing 48 main()49int main() { 50 testing::test_get_in_anon_ns_const_field(); 51 52 return boost::report_errors(); 53 } 54 55 56