| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// { dg-add-options no_pch } |
| 3 |
|
| 4 |
#include <variant> |
| 5 |
|
| 6 |
// P2062R2 Inheriting from std::variant (resolving LWG 3052) |
| 7 |
|
| 8 |
#if __cpp_lib_variant < 202102L |
| 9 |
#error __cpp_lib_variant has the wrong value in <variant> |
| 10 |
#endif |
| 11 |
|
| 12 |
struct V : std::variant<int> { |
| 13 |
using std::variant<int>::variant; |
| 14 |
}; |
| 15 |
|
| 16 |
constexpr int |
| 17 |
test01() |
| 18 |
{ |
| 19 |
V v = 42; |
| 20 |
return std::visit([](int&){ return 17; }, v); |
| 21 |
} |
| 22 |
static_assert( test01() == 17 ); |
| 23 |
|
| 24 |
constexpr int |
| 25 |
test02() |
| 26 |
{ |
| 27 |
const V c = 77; |
| 28 |
std::variant<char*, long> x = 88L; |
| 29 |
return std::visit([](auto&& a, auto&& b) { |
| 30 |
if constexpr (std::is_same_v<decltype(a), const int&&>) |
| 31 |
if constexpr (std::is_same_v<decltype(b), long&&>) |
| 32 |
return 99; |
| 33 |
return 0; |
| 34 |
}, |
| 35 |
std::move(c), std::move(x)); |
| 36 |
} |
| 37 |
static_assert( test02() == 99 ); |