61 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9 10// <type_traits>11// UNSUPPORTED: c++03, c++11, c++14, c++1712 13#include <type_traits>14 15#include "test_macros.h"16 17struct A {};18struct B {19public:20 operator A() { return a; } A a;21};22 23class C { };24class D {25public:26 operator C() noexcept { return c; } C c;27};28 29int main(int, char**) {30 static_assert((std::is_nothrow_convertible<int, double>::value), "");31 static_assert(!(std::is_nothrow_convertible<int, char*>::value), "");32 33 static_assert(!(std::is_nothrow_convertible<A, B>::value), "");34 static_assert((std::is_nothrow_convertible<D, C>::value), "");35 36 static_assert((std::is_nothrow_convertible_v<int, double>), "");37 static_assert(!(std::is_nothrow_convertible_v<int, char*>), "");38 39 static_assert(!(std::is_nothrow_convertible_v<A, B>), "");40 static_assert((std::is_nothrow_convertible_v<D, C>), "");41 42 static_assert((std::is_nothrow_convertible_v<const void, void>), "");43 static_assert((std::is_nothrow_convertible_v<volatile void, void>), "");44 static_assert((std::is_nothrow_convertible_v<void, const void>), "");45 static_assert((std::is_nothrow_convertible_v<void, volatile void>), "");46 47 static_assert(!(std::is_nothrow_convertible_v<int[], double[]>), "");48 static_assert(!(std::is_nothrow_convertible_v<int[], int[]>), "");49 static_assert(!(std::is_nothrow_convertible_v<int[10], int[10]>), "");50 static_assert(!(std::is_nothrow_convertible_v<int[10], double[10]>), "");51 static_assert(!(std::is_nothrow_convertible_v<int[5], double[10]>), "");52 static_assert(!(std::is_nothrow_convertible_v<int[10], A[10]>), "");53 54 typedef void V();55 typedef int I();56 static_assert(!(std::is_nothrow_convertible_v<V, V>), "");57 static_assert(!(std::is_nothrow_convertible_v<V, I>), "");58 59 return 0;60}61