1189251Ssam// { dg-options "-std=gnu++11" }
2189251Ssam
3252726Srpaulo// Copyright (C) 2010-2015 Free Software Foundation, Inc.
4189251Ssam//
5252726Srpaulo// This file is part of the GNU ISO C++ Library.  This library is free
6252726Srpaulo// software; you can redistribute it and/or modify it under the
7189251Ssam// terms of the GNU General Public License as published by the
8189251Ssam// Free Software Foundation; either version 3, or (at your option)
9214734Srpaulo// any later version.
10189251Ssam//
11214734Srpaulo// This library is distributed in the hope that it will be useful,
12214734Srpaulo// but WITHOUT ANY WARRANTY; without even the implied warranty of
13214734Srpaulo// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14214734Srpaulo// GNU General Public License for more details.
15214734Srpaulo//
16214734Srpaulo// You should have received a copy of the GNU General Public License along
17214734Srpaulo// with this library; see the file COPYING3.  If not see
18252726Srpaulo// <http://www.gnu.org/licenses/>.
19214734Srpaulo
20189251Ssam#include <list>
21189251Ssam#include <testsuite_hooks.h>
22189251Ssam
23214734Srpaulotemplate <class T>
24189251Ssam  struct C
25252726Srpaulo  {
26209158Srpaulo    T t_;
27252726Srpaulo
28189251Ssam    template <class U,
29252726Srpaulo              class = typename std::enable_if
30252726Srpaulo                    <
31252726Srpaulo                        !std::is_lvalue_reference<U>::value
32252726Srpaulo                    >::type>
33252726Srpaulo      C(U&& u) : t_(std::forward<T>(std::move(u).get())) {}
34252726Srpaulo  };
35252726Srpaulo
36252726Srpauloclass A
37252726Srpaulo{
38252726Srpaulo  int data_;
39252726Srpaulopublic:
40252726Srpaulo  explicit
41252726Srpaulo  A(int data = 1)
42252726Srpaulo  : data_(data) { }
43252726Srpaulo
44252726Srpaulo  ~A() { data_ = -1; }
45252726Srpaulo
46252726Srpaulo  void test() const
47252726Srpaulo  {
48252726Srpaulo    bool test __attribute__((unused)) = true;
49252726Srpaulo    VERIFY( data_ == 3 );
50252726Srpaulo  }
51252726Srpaulo};
52252726Srpaulo
53252726Srpauloclass Awrap
54252726Srpaulo{
55252726Srpaulo  A a_;
56252726Srpaulopublic:
57252726Srpaulo  explicit Awrap(const A& a) : a_(a) { }
58252726Srpaulo  A get() const { return a_; }
59252726Srpaulo};
60252726Srpaulo
61252726Srpaulotemplate <class C>
62252726Srpaulovoid test(C c)
63252726Srpaulo{
64252726Srpaulo  c.t_.test();
65252726Srpaulo}
66252726Srpaulo
67252726Srpaulo// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html
68252726Srpaulo// Test B.
69252726Srpauloint main()
70252726Srpaulo{
71252726Srpaulo  std::list<C<A> > list;
72252726Srpaulo  A a(3);
73252726Srpaulo  C<A> c((Awrap(a)));
74252726Srpaulo  list.push_back(c);
75252726Srpaulo  test(c);
76189251Ssam  test(list.front());
77214734Srpaulo}
78189251Ssam