xref: /llvm-project/libcxx/test/std/utilities/variant/variant.visit/robust_against_adl.pass.cpp (revision ec350ad418a24f70c88758259c774a1e11c06d74)
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 // template <class Visitor, class... Variants>
13 // constexpr see below visit(Visitor&& vis, Variants&&... vars);
14 
15 #include <variant>
16 
17 #include "test_macros.h"
18 
19 struct Incomplete;
20 template<class T> struct Holder { T t; };
21 
test(bool do_it)22 constexpr bool test(bool do_it)
23 {
24     if (do_it) {
25         std::variant<Holder<Incomplete>*, int> v = nullptr;
26         std::visit([](auto){}, v);
27         std::visit([](auto) -> Holder<Incomplete>* { return nullptr; }, v);
28 #if TEST_STD_VER > 17
29         std::visit<void>([](auto){}, v);
30         std::visit<void*>([](auto) -> Holder<Incomplete>* { return nullptr; }, v);
31 #endif
32     }
33     return true;
34 }
35 
main(int,char **)36 int main(int, char**)
37 {
38     test(true);
39 #if TEST_STD_VER > 17
40     static_assert(test(true));
41 #endif
42     return 0;
43 }
44