| 1 | // Copyright 2023 Peter Dimov |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/core/launder.hpp> |
| 6 | #include <boost/core/lightweight_test.hpp> |
| 7 | #include <new> |
| 8 | |
| 9 | struct X |
| 10 | { |
| 11 | int v_; |
| 12 | |
| 13 | explicit X( int v = 0 ): v_( v ) {} |
| 14 | }; |
| 15 | |
| 16 | int main() |
| 17 | { |
| 18 | X x; |
| 19 | |
| 20 | typedef X const CX; |
| 21 | |
| 22 | ::new( &x ) CX( 1 ); |
| 23 | X const* px1 = &x; |
| 24 | |
| 25 | BOOST_TEST_EQ( px1->v_, 1 ); |
| 26 | |
| 27 | ::new( &x ) CX( 2 ); |
| 28 | X const* px2 = boost::core::launder( p: px1 ); |
| 29 | |
| 30 | BOOST_TEST_EQ( px1, px2 ); |
| 31 | BOOST_TEST_EQ( px2->v_, 2 ); |
| 32 | |
| 33 | return boost::report_errors(); |
| 34 | } |
| 35 |
