brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · ea761b2 Raw
42 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s2 3template<typename T>4constexpr bool is_ptr_v = false;5 6template<typename T>7constexpr bool is_ptr_v<T*> = true;8 9template<typename T, typename U>10constexpr bool is_same_v = false;11 12template<typename T>13constexpr bool is_same_v<T, T> = true;14 15template<typename T> requires is_ptr_v<T> // expected-note   {{because 'is_ptr_v<int>' evaluated to false}}16                         // expected-note@-1{{because 'is_ptr_v<char>' evaluated to false}}17auto dereference(T t) { // expected-note   {{candidate template ignored: constraints not satisfied [with T = int]}}18                        // expected-note@-1{{candidate template ignored: constraints not satisfied [with T = char]}}19  return *t;20}21 22static_assert(is_same_v<decltype(dereference<int*>(nullptr)), int>);23static_assert(is_same_v<decltype(dereference(2)), int>); // expected-error {{no matching function for call to 'dereference'}}24static_assert(is_same_v<decltype(dereference<char>('a')), char>); // expected-error {{no matching function for call to 'dereference'}}25 26template<typename T> requires (T{} + T{}) // expected-note {{because substituted constraint expression is ill-formed: invalid operands to binary expression ('A' and 'A')}}27auto foo(T t) { // expected-note {{candidate template ignored: constraints not satisfied [with T = A]}}28  return t + t;29}30 31 32template<typename T> requires (!((T{} - T{}) && (T{} + T{})) || false)33// expected-note@-1{{because substituted constraint expression is ill-formed: invalid operands to binary expression ('A' and 'A')}}34// expected-note@-2{{and 'false' evaluated to false}}35auto bar(T t) { // expected-note {{candidate template ignored: constraints not satisfied [with T = A]}}36  return t + t;37}38 39struct A { };40 41static_assert(foo(A{})); // expected-error {{no matching function for call to 'foo'}}42static_assert(bar(A{})); // expected-error {{no matching function for call to 'bar'}}