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:
@@ -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 ]
|
||||
|
||||
30
test/common/ops_unions.cpp
Normal file
30
test/common/ops_unions.cpp
Normal 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;
|
||||
}
|
||||
32
test/common/ops_unrestricted_unions.cpp
Normal file
32
test/common/ops_unrestricted_unions.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user