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, c++17, c++20, c++23
10// The tested functionality needs deducing this.
11// UNSUPPORTED: clang-17
12// XFAIL: apple-clang
13
14// <variant>
15
16// class variant;
17// template<class Self, class Visitor>
18// constexpr decltype(auto) visit(this Self&&, Visitor&&); // since C++26
19// template<class R, class Self, class Visitor>
20// constexpr R visit(this Self&&, Visitor&&); // since C++26
21
22#include <variant>
23
24#include "test_macros.h"
25
26struct Incomplete;
27template <class T>
28struct Holder {
29 T t;
30};
31
32constexpr bool test(bool do_it) {
33 if (do_it) {
34 std::variant<Holder<Incomplete>*, int> v = nullptr;
35
36 v.visit([](auto) {});
37 v.visit([](auto) -> Holder<Incomplete>* { return nullptr; });
38 v.visit<void>([](auto) {});
39 v.visit<void*>([](auto) -> Holder<Incomplete>* { return nullptr; });
40 }
41 return true;
42}
43
44int main(int, char**) {
45 test(do_it: true);
46 static_assert(test(true));
47
48 return 0;
49}
50

source code of libcxx/test/std/utilities/variant/variant.visit.member/robust_against_adl.pass.cpp