brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · e207c4b Raw
64 lines · cpp
1// RUN:  %clang_cc1 -std=c++2a -verify %s2 3struct S2 {};4// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'S1<int>' to 'const S2' for 1st argument}}5// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'S1<int>' to 'S2' for 1st argument}}6// expected-note@-3 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}7 8template<typename T>9struct S1 {10  void foo() const requires true {}11  void foo() const requires false {}12  void bar() const requires false {}13  // expected-note@-1 {{because 'false' evaluated to false}}14  operator bool() const requires true { return true; }15  explicit operator bool() const requires false;16  explicit operator S2() const requires false;17  // expected-note@-1 {{candidate function not viable: constraints not satisfied}}18  // expected-note@-2 {{because 'false' evaluated to false}}19};20 21void foo() {22  S1<int>().foo();23  S1<int>().bar();24  // expected-error@-1 {{invalid reference to function 'bar': constraints not satisfied}}25  (void) static_cast<bool>(S1<int>());26  (void) static_cast<S2>(S1<int>());27  // expected-error@-1 {{no matching conversion for static_cast from 'S1<int>' to 'S2'}}28}29 30// Test that constraints are checked before implicit conversions are formed.31 32template<typename T>33struct invalid_template { using X = typename T::non_existant; };34struct A {35  template<typename T, bool=invalid_template<T>::aadasas>36  operator T() {}37};38 39template<typename>40struct WrapsStatics {41  static void foo(int) requires false;42  static void foo(A) requires true;43};44 45template<typename T>46struct S {47  void foo(int) requires false;48  void foo(A) requires true;49  S(A) requires false;50  S(double) requires true;51  ~S() requires false;52  ~S() requires true;53  operator int() requires true;54  operator int() requires false;55};56 57void bar() {58  WrapsStatics<int>::foo(A{});59  S<int>{1.}.foo(A{});60 61  S<int> s = 1;62  int a = s;63}64