Debian Codegraph @

clang/test/Parser/cxx2a-concept-declaration.cpp

raw
1 // Support parsing of concepts
2
3 // RUN: %clang_cc1 -std=c++20 -verify %s
4 template<typename T> concept C1 = true; // expected-note 2{{previous}}
5
6 template<typename T> concept C1 = true; // expected-error{{redefinition}}
7
8 template<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
12 struct S1 {
13 template<typename T> concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}}
14 };
15
16 extern "C++" {
17 template<typename T> concept C1 = true; // expected-error{{redefinition}}
18 }
19
20 template<typename A>
21 template<typename B>
22 concept C2 = true; // expected-error {{extraneous template parameter list in concept definition}}
23
24 template<typename T> concept C3 = true; // expected-note {{previous}} expected-note {{previous}}
25 int C3; // expected-error {{redefinition}}
26 struct C3 {}; // expected-error {{redefinition}}
27
28 struct C4 {}; // expected-note{{previous definition is here}}
29 template<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 specialization
33 // and explicit instantiation of concepts.
34
35 template<typename T, T v>
36 struct integral_constant { static constexpr T value = v; };
37
38 namespace N {
39 template<typename T> concept C5 = true;
40 }
41 using N::C5;
42
43 template <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
47 template<typename T> concept bool C7 = true;
48 // expected-error@-1{{ISO C++ does not permit the 'bool' keyword after 'concept'}}
49
50 template<> 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
53 template<> concept C7<int> = false;
54 // expected-error@-1{{name defined in concept definition must be an identifier}}
55
56 template<typename T> concept N::C9 = false;
57 // expected-error@-1{{name defined in concept definition must be an identifier}}
58
59 class A { };
60 // expected-note@-1{{'A' declared here}}
61
62 template<typename T> concept A::C10 = false;
63 // expected-error@-1{{expected namespace name}}
64
65 template<typename T> concept operator int = false;
66 // expected-error@-1{{name defined in concept definition must be an identifier}}
67
68 template<bool x> concept C11 = 2; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
69 template<bool x> concept C12 = 2 && x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
70 template<bool x> concept C13 = x || 2 || x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
71 template<bool x> concept C14 = 8ull && x || x; // expected-error {{atomic constraint must be of type 'bool' (found 'unsigned long long')}}
72 template<typename T> concept C15 = sizeof(T); // expected-error {{atomic constraint must be of type 'bool'}}
73 template<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}}
77 template<typename T> concept C17 = T{};
78 static_assert(!C17<bool>);
79 template<typename T> concept C18 = (bool&&)true;
80 static_assert(C18<int>);
81 template<typename T> concept C19 = (const bool&)true;
82 static_assert(C19<int>);
83 template<typename T> concept C20 = (const bool)true;
84 static_assert(C20<int>);
85 template <bool c> concept C21 = integral_constant<bool, c>::value && true;
86 static_assert(C21<true>);
87 static_assert(!C21<false>);
88 template <bool c> concept C22 = integral_constant<bool, c>::value;
89 static_assert(C22<true>);
90 static_assert(!C22<false>);
91
92 template <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