1//
2// sp_constexpr_test.cpp
3//
4// Copyright 2017 Peter Dimov
5//
6// Distributed under the Boost Software License, Version 1.0.
7// See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt
9//
10
11#include <boost/config.hpp>
12#include <boost/config/workaround.hpp>
13
14#define HAVE_CONSTEXPR_INIT
15
16#if defined( BOOST_NO_CXX11_CONSTEXPR )
17# undef HAVE_CONSTEXPR_INIT
18#endif
19
20#if BOOST_WORKAROUND( BOOST_MSVC, < 1930 )
21# undef HAVE_CONSTEXPR_INIT
22#endif
23
24#if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR )
25# undef HAVE_CONSTEXPR_INIT
26#endif
27
28#if !defined( HAVE_CONSTEXPR_INIT )
29
30int main()
31{
32}
33
34#else
35
36#include <boost/shared_ptr.hpp>
37#include <boost/weak_ptr.hpp>
38#include <boost/enable_shared_from_this.hpp>
39#include <boost/core/lightweight_test.hpp>
40
41struct X: public boost::enable_shared_from_this<X>
42{
43};
44
45struct Z
46{
47 Z();
48};
49
50static Z z;
51
52static boost::shared_ptr<X> p1;
53static boost::weak_ptr<X> p2;
54
55#if !defined( BOOST_NO_CXX11_NULLPTR )
56 static boost::shared_ptr<X> p3( nullptr );
57#endif
58
59Z::Z()
60{
61 p1.reset( p: new X );
62 p2 = p1;
63#if !defined( BOOST_NO_CXX11_NULLPTR )
64 p3.reset( p: new X );
65#endif
66}
67
68int main()
69{
70 BOOST_TEST( p1.get() != 0 );
71 BOOST_TEST_EQ( p1.use_count(), 1 );
72
73 BOOST_TEST_EQ( p2.use_count(), 1 );
74 BOOST_TEST_EQ( p2.lock(), p1 );
75
76#if !defined( BOOST_NO_CXX11_NULLPTR )
77
78 BOOST_TEST( p3.get() != 0 );
79 BOOST_TEST_EQ( p3.use_count(), 1 );
80
81#endif
82
83 return boost::report_errors();
84}
85
86#endif // #if defined( BOOST_NO_CXX11_CONSEXPR )
87

source code of boost/libs/smart_ptr/test/sp_constexpr_test.cpp