1 // Copyright (C) 2015-2019 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++11 } }
21 #include <testsuite_hooks.h>
24 bool not_enabled(T
& t
)
26 #if __cpp_lib_enable_shared_from_this >= 201603
27 return t
.weak_from_this().expired();
32 } catch (const std::bad_weak_ptr
&) {
38 struct A
: std::enable_shared_from_this
<A
> { };
39 struct B
: std::enable_shared_from_this
<B
> { };
44 auto d
= std::make_shared
<D
>();
45 VERIFY( not_enabled( static_cast<A
&>(*d
) ) );
46 VERIFY( not_enabled( static_cast<const A
&>(*d
) ) );
47 VERIFY( not_enabled( static_cast<B
&>(*d
) ) );
48 VERIFY( not_enabled( static_cast<const B
&>(*d
) ) );
51 struct E
: std::__enable_shared_from_this
<E
> { };
52 struct F
: std::__enable_shared_from_this
<F
> { };
57 auto g
= std::make_shared
<G
>();
58 VERIFY( not_enabled( static_cast<E
&>(*g
) ) );
59 VERIFY( not_enabled( static_cast<const E
&>(*g
) ) );
60 VERIFY( not_enabled( static_cast<F
&>(*g
) ) );
61 VERIFY( not_enabled( static_cast<const F
&>(*g
) ) );
68 auto h
= std::make_shared
<H
>();
69 VERIFY( not_enabled( static_cast<A
&>(*h
) ) );
70 VERIFY( not_enabled( static_cast<const A
&>(*h
) ) );
71 VERIFY( not_enabled( static_cast<B
&>(*h
) ) );
72 VERIFY( not_enabled( static_cast<const B
&>(*h
) ) );
73 VERIFY( not_enabled( static_cast<E
&>(*h
) ) );
74 VERIFY( not_enabled( static_cast<const E
&>(*h
) ) );
75 VERIFY( not_enabled( static_cast<F
&>(*h
) ) );
76 VERIFY( not_enabled( static_cast<const F
&>(*h
) ) );