Files
libcxx/test/std/utilities/variant/variant.variant/variant.ctor/conv.fail.cpp
Zhihao Yuan f8f62ac93c [libc++] Implement P0608R3 - A sane variant converting constructor
Summary:
Prefer user-defined conversions over narrowing conversions and conversions to bool.

References:
 http://wg21.link/p0608

Reviewers: EricWF, mpark, mclow.lists

Reviewed By: mclow.lists

Subscribers: zoecarver, ldionne, libcxx-commits, cfe-commits, christof

Differential Revision: https://reviews.llvm.org/D44865

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363692 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 15:26:50 +00:00

40 lines
1.6 KiB
C++

// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14
// <variant>
// template <class ...Types> class variant;
// template <class T> constexpr variant(T&&) noexcept(see below);
#include <variant>
#include <string>
#include <memory>
int main(int, char**)
{
std::variant<int, int> v1 = 1; // expected-error {{no viable conversion}}
std::variant<long, long long> v2 = 1; // expected-error {{no viable conversion}}
std::variant<char> v3 = 1; // expected-error {{no viable conversion}}
std::variant<std::string, float> v4 = 1; // expected-error {{no viable conversion}}
std::variant<std::string, double> v5 = 1; // expected-error {{no viable conversion}}
std::variant<std::string, bool> v6 = 1; // expected-error {{no viable conversion}}
std::variant<int, bool> v7 = "meow"; // expected-error {{no viable conversion}}
std::variant<int, bool const> v8 = "meow"; // expected-error {{no viable conversion}}
std::variant<int, bool volatile> v9 = "meow"; // expected-error {{no viable conversion}}
std::variant<bool> v10 = std::true_type(); // expected-error {{no viable conversion}}
std::variant<bool> v11 = std::unique_ptr<char>(); // expected-error {{no viable conversion}}
std::variant<bool> v12 = nullptr; // expected-error {{no viable conversion}}
}