1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14 |
10 | |
11 | // <variant> |
12 | |
13 | // template <class ...Types> class variant; |
14 | |
15 | // Make sure that the implicitly-generated CTAD works. |
16 | |
17 | // We make sure that it is not ill-formed, however we still produce a warning for |
18 | // this one because explicit construction from a variant using CTAD is ambiguous |
19 | // (in the sense that the programmer intent is not clear). |
20 | // ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-ctad-maybe-unsupported |
21 | |
22 | #include <variant> |
23 | |
24 | #include "test_macros.h" |
25 | |
26 | int main(int, char**) { |
27 | // This is the motivating example from P0739R0 |
28 | { |
29 | std::variant<int, double> v1(3); |
30 | std::variant v2 = v1; |
31 | ASSERT_SAME_TYPE(decltype(v2), std::variant<int, double>); |
32 | } |
33 | |
34 | { |
35 | std::variant<int, double> v1(3); |
36 | std::variant v2 = std::variant(v1); // Technically valid, but intent is ambiguous! |
37 | ASSERT_SAME_TYPE(decltype(v2), std::variant<int, double>); |
38 | } |
39 | |
40 | return 0; |
41 | } |
42 | |