67 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -x c++ -Wno-constant-logical-operand -verify %s2 3template<typename T> concept C =4sizeof(T) == 4 && !true; // requires atomic constraints sizeof(T) == 4 and !true5 6template<typename T> concept C2 = sizeof(T); // expected-error{{atomic constraint must be of type 'bool' (found }}7 8template<typename T> struct S {9 constexpr operator bool() const { return true; }10};11 12// expected-error@+3{{atomic constraint must be of type 'bool' (found 'S<int>')}}13// expected-note@#FINST{{while checking constraint satisfaction}}14// expected-note@#FINST{{while substituting deduced template arguments into function template 'f' [with T = int]}}15template<typename T> requires (S<T>{})16void f(T);17void f(long);18 19// Ensure this applies to operator && as well.20// expected-error@+3{{atomic constraint must be of type 'bool' (found 'S<int>')}}21// expected-note@#F2INST{{while checking constraint satisfaction}}22// expected-note@#F2INST{{while substituting deduced template arguments into function template 'f2' [with T = int]}}23template<typename T> requires (S<T>{} && true)24void f2(T);25void f2(long);26 27template<typename T> requires requires {28 requires S<T>{};29 // expected-error@-1{{atomic constraint must be of type 'bool' (found 'S<int>')}}30 // expected-note@-2{{while checking the satisfaction}}31 // expected-note@-3{{while checking the satisfaction of nested requirement}}32 // expected-note@-5{{while substituting template arguments}}33 // expected-note@#F3INST{{while checking constraint satisfaction}}34 // expected-note@#F3INST{{while substituting deduced template arguments into function template 'f3' [with T = int]}}35 //36}37void f3(T);38void f3(long);39 40// Doesn't diagnose, since this is no longer a compound requirement.41template<typename T> requires (bool(1 && 2))42void f4(T);43void f4(long);44 45void g() {46 f(0); // #FINST47 f2(0); // #F2INST48 f3(0); // #F3INST49 f4(0);50}51 52template<typename T>53auto Nullptr = nullptr;54 55template<typename T> concept NullTy = Nullptr<T>;56// expected-error@-1{{atomic constraint must be of type 'bool' (found }}57// expected-note@+1{{while checking the satisfaction}}58static_assert(NullTy<int>);59 60template<typename T>61auto Struct = S<T>{};62 63template<typename T> concept StructTy = Struct<T>;64// expected-error@-1{{atomic constraint must be of type 'bool' (found 'S<int>')}}65// expected-note@+1{{while checking the satisfaction}}66static_assert(StructTy<int>);67