]>
Commit | Line | Data |
---|---|---|
1e59de90 | 1 | // Copyright (c) 2020-2022 Antony Polukhin |
20effc67 TL |
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 | #include <boost/core/lightweight_test.hpp> | |
7 | ||
8 | #include <boost/pfr/core.hpp> | |
9 | ||
10 | #include <string> | |
11 | #include <typeindex> | |
12 | #include <type_traits> | |
13 | ||
14 | namespace testing { | |
15 | ||
16 | namespace { | |
17 | ||
18 | struct other_anon { | |
19 | int data; | |
20 | }; | |
21 | ||
22 | struct anon { | |
23 | other_anon a; | |
24 | const other_anon b; | |
25 | }; | |
26 | ||
27 | void test_in_anon_ns_const_field() { | |
28 | anon x{{1}, {2}}; | |
29 | ||
30 | auto v = boost::pfr::structure_tie(x); | |
31 | using v_type = decltype(v); | |
32 | using expected_type = std::tuple<other_anon&, const other_anon&>; | |
33 | ||
34 | // Use runtime check to make sure that Loophole fails to compile structure_tie | |
35 | BOOST_TEST(typeid(expected_type) == typeid(v_type)); | |
36 | } | |
37 | ||
38 | } // anonymous namespace | |
39 | ||
40 | void test_in_non_non_ns_const_field() { | |
41 | anon x{{1}, {2}}; | |
42 | ||
43 | auto v = boost::pfr::structure_tie(x); | |
44 | using v_type = decltype(v); | |
45 | using expected_type = std::tuple<other_anon&, const other_anon&>; | |
46 | ||
47 | // Use runtime check to make sure that Loophole fails to compile structure_tie | |
48 | BOOST_TEST(typeid(expected_type) == typeid(v_type)); | |
49 | } | |
50 | ||
51 | } // namespace testing | |
52 | ||
53 | int main() { | |
54 | testing::test_in_anon_ns_const_field(); | |
55 | testing::test_in_non_non_ns_const_field(); | |
56 | ||
57 | return boost::report_errors(); | |
58 | } | |
59 | ||
60 |