96 lines · cpp
1// Support parsing of concepts2 3// RUN: %clang_cc1 -std=c++20 -verify %s4template<typename T> concept C1 = true; // expected-note 2{{previous}}5 6template<typename T> concept C1 = true; // expected-error{{redefinition}}7 8template<concept T> concept D1 = true;9// expected-error@-1{{expected template parameter}}10// expected-error@-2{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}}11 12struct S1 {13 template<typename T> concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}}14};15 16extern "C++" {17 template<typename T> concept C1 = true; // expected-error{{redefinition}}18}19 20template<typename A>21template<typename B>22concept C2 = true; // expected-error {{extraneous template parameter list in concept definition}}23 24template<typename T> concept C3 = true; // expected-note {{previous}} expected-note {{previous}}25int C3; // expected-error {{redefinition}}26struct C3 {}; // expected-error {{redefinition}}27 28struct C4 {}; // expected-note{{previous definition is here}}29template<typename T> concept C4 = true;30// expected-error@-1{{redefinition of 'C4' as different kind of symbol}}31 32// TODO: Add test to prevent explicit specialization, partial specialization33// and explicit instantiation of concepts.34 35template<typename T, T v>36struct integral_constant { static constexpr T value = v; };37 38namespace N {39 template<typename T> concept C5 = true;40}41using N::C5;42 43template <bool word> concept C6 = integral_constant<bool, wor>::value;44// expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}}45// expected-note@-2{{'word' declared here}}46 47template<typename T> concept bool C7 = true;48// expected-error@-1{{ISO C++ does not permit the 'bool' keyword after 'concept'}}49 50template<> concept C8 = false;51// expected-error@-1{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}}52 53template<> concept C7<int> = false;54// expected-error@-1{{name defined in concept definition must be an identifier}}55 56template<typename T> concept N::C9 = false;57// expected-error@-1{{name defined in concept definition must be an identifier}}58 59class A { };60// expected-note@-1{{'A' declared here}}61 62template<typename T> concept A::C10 = false;63// expected-error@-1{{expected namespace name}}64 65template<typename T> concept operator int = false;66// expected-error@-1{{name defined in concept definition must be an identifier}}67 68template<bool x> concept C11 = 2; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}69template<bool x> concept C12 = 2 && x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}70template<bool x> concept C13 = x || 2 || x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}71template<bool x> concept C14 = 8ull && x || x; // expected-error {{atomic constraint must be of type 'bool' (found 'unsigned long long')}}72template<typename T> concept C15 = sizeof(T); // expected-error {{atomic constraint must be of type 'bool'}}73template<typename T> concept C16 = true && (0 && 0); // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}74// expected-warning@-1{{use of logical '&&' with constant operand}}75// expected-note@-2{{use '&' for a bitwise operation}}76// expected-note@-3{{remove constant to silence this warning}}77template<typename T> concept C17 = T{};78static_assert(!C17<bool>);79template<typename T> concept C18 = (bool&&)true;80static_assert(C18<int>);81template<typename T> concept C19 = (const bool&)true;82static_assert(C19<int>);83template<typename T> concept C20 = (const bool)true;84static_assert(C20<int>);85template <bool c> concept C21 = integral_constant<bool, c>::value && true;86static_assert(C21<true>);87static_assert(!C21<false>);88template <bool c> concept C22 = integral_constant<bool, c>::value;89static_assert(C22<true>);90static_assert(!C22<false>);91 92template <bool word> concept C23 = integral_constant<bool, wor>::value;93// expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}}94// expected-note@-2{{'word' declared here}}95 96