| 1 |
// Copyright (C) 2018-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 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) |
| 7 |
// any later version. |
| 8 |
|
| 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. |
| 13 |
|
| 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/>. |
| 17 |
|
| 18 |
// { dg-do compile { target c++11 } } |
| 19 |
|
| 20 |
#include <functional> |
| 21 |
|
| 22 |
// LWG 2993. reference_wrapper<T> conversion from T&& |
| 23 |
|
| 24 |
static_assert(std::is_convertible<std::reference_wrapper<int>, |
| 25 |
std::reference_wrapper<const int>>::value, |
| 26 |
"LWG 2993 enables qualification conversions"); |
| 27 |
|
| 28 |
// The comments below are taken from the issue discussion and describe the |
| 29 |
// behaviour before the resolution of LWG 2993. There should be no errors now. |
| 30 |
|
| 31 |
struct convertible_from_int { convertible_from_int(int) { } }; |
| 32 |
|
| 33 |
void |
| 34 |
test01() |
| 35 |
{ |
| 36 |
|
| 37 |
void meow(std::reference_wrapper<int>); //#1 |
| 38 |
void meow(convertible_from_int); //#2 |
| 39 |
// error, ambiguous; would unambiguously call #2 if #1 instead took int& |
| 40 |
meow(0); |
| 41 |
} |
| 42 |
|
| 43 |
void |
| 44 |
test02() |
| 45 |
{ |
| 46 |
std::reference_wrapper<int> purr(); // { dg-warning "empty parentheses" } |
| 47 |
|
| 48 |
// error, ambiguous: ICS exists from int prvalue to |
| 49 |
// reference_wrapper<int> and from reference_wrapper<int> to int |
| 50 |
auto x = true ? purr() : 0; |
| 51 |
|
| 52 |
// error: no member 'type' because the conditional |
| 53 |
// expression is ill-formed |
| 54 |
using t = typename std::common_type<std::reference_wrapper<int>, int>::type; |
| 55 |
} |