2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

More tests on unions (refs #22)

This commit is contained in:
Antony Polukhin
2018-05-30 23:04:03 +03:00
parent e7abff68f6
commit ea47144b60
3 changed files with 73 additions and 1 deletions

View File

@@ -59,9 +59,19 @@ test-suite pfr
[ compile-fail common/virtual_functions.cpp : $(CLASSIC_FLAT_DEF) : flat_virtual_functions ]
[ compile-fail common/virtual_functions.cpp : $(LOOPHOLE_FLAT_DEF) : flat_lh_virtual_functions ]
[ compile-fail common/virtual_functions.cpp : $(CLASSIC_PREC_DEF) : precise_virtual_functions ]
[ compile-fail common/virtual_functions.cpp : $(CLASSIC_PREC_DEF) : precise_virtual_functions ]
[ compile-fail common/virtual_functions.cpp : $(LOOPHOLE_PREC_DEF) : precise_lh_virtual_functions ]
[ compile-fail common/ops_unions.cpp : $(CLASSIC_FLAT_DEF) : flat_unions ]
[ compile-fail common/ops_unions.cpp : $(LOOPHOLE_FLAT_DEF) : flat_lh_unions ]
[ compile-fail common/ops_unions.cpp : $(CLASSIC_PREC_DEF) : precise_unions ]
[ compile-fail common/ops_unions.cpp : $(LOOPHOLE_PREC_DEF) : precise_lh_unions ]
[ compile-fail common/ops_unrestricted_unions.cpp : $(CLASSIC_FLAT_DEF) : flat_unrestricted_unions ]
[ compile-fail common/ops_unrestricted_unions.cpp : $(LOOPHOLE_FLAT_DEF) : flat_lh_unrestricted_unions ]
[ compile-fail common/ops_unrestricted_unions.cpp : $(CLASSIC_PREC_DEF) : precise_unrestricted_unions ]
[ compile-fail common/ops_unrestricted_unions.cpp : $(LOOPHOLE_PREC_DEF) : precise_lh_unrestricted_unions ]
[ compile-fail common/non_std_layout.cpp : $(CLASSIC_FLAT_DEF) : flat_non_standard_layout ]
[ compile-fail common/non_std_layout.cpp : $(LOOPHOLE_FLAT_DEF) : flat_lh_non_standard_layout ]
[ run common/non_std_layout.cpp : : : $(CLASSIC_PREC_DEF) : precise_non_standard_layout ]

View File

@@ -0,0 +1,30 @@
// Copyright (c) 2018 Antony Polukhin
//
// 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 <string>
#ifdef BOOST_PFR_TEST_FLAT
#include <boost/pfr/flat/ops.hpp>
using namespace boost::pfr::flat_ops;
#endif
#ifdef BOOST_PFR_TEST_PRECISE
#include <boost/pfr/precise/ops.hpp>
using namespace boost::pfr::ops;
#endif
union test_union {
const char* c;
int i;
};
int main() {
struct two_unions {
test_union u1, u2;
};
two_unions v{{""}, {""}};
return v == v;
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) 2018 Antony Polukhin
//
// 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 <string>
#ifdef BOOST_PFR_TEST_FLAT
#include <boost/pfr/flat/ops.hpp>
using namespace boost::pfr::flat_ops;
#endif
#ifdef BOOST_PFR_TEST_PRECISE
#include <boost/pfr/precise/ops.hpp>
using namespace boost::pfr::ops;
#endif
union test_unrestricted_union {
int i;
std::string s;
};
int main() {
struct two_unions {
test_unrestricted_union u1, u2;
};
// Not calling the destructor intentionally!
auto v = new two_unions{{1}, {1}};
return *v == *v;
}