Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame^] | 1 | // Support parsing of concepts |
| 2 | |
| 3 | // RUN: %clang_cc1 -std=c++2a -fconcepts-ts -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 | template<template<typename> concept T> concept D2 = true; |
| 13 | // expected-error@-1{{expected identifier}} |
| 14 | // expected-error@-2{{template template parameter requires 'class' after the parameter list}} |
| 15 | // expected-error@-3{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}} |
| 16 | |
| 17 | template<typename T> concept C2 = 0.f; // expected-error {{constraint expression must be of type 'bool' but is of type 'float'}} |
| 18 | |
| 19 | struct S1 { |
| 20 | template<typename T> concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}} |
| 21 | }; |
| 22 | |
| 23 | extern "C++" { |
| 24 | template<typename T> concept C1 = true; // expected-error{{redefinition}} |
| 25 | } |
| 26 | |
| 27 | template<typename A> |
| 28 | template<typename B> |
| 29 | concept C4 = true; // expected-error {{extraneous template parameter list in concept definition}} |
| 30 | |
| 31 | template<typename T> concept C5 = true; // expected-note {{previous}} expected-note {{previous}} |
| 32 | int C5; // expected-error {{redefinition}} |
| 33 | struct C5 {}; // expected-error {{redefinition}} |
| 34 | |
| 35 | struct C6 {}; // expected-note{{previous definition is here}} |
| 36 | template<typename T> concept C6 = true; |
| 37 | // expected-error@-1{{redefinition of 'C6' as different kind of symbol}} |
| 38 | |
| 39 | // TODO: Add test to prevent explicit specialization, partial specialization |
| 40 | // and explicit instantiation of concepts. |
| 41 | |
| 42 | template<typename T, T v> |
| 43 | struct integral_constant { static constexpr T value = v; }; |
| 44 | |
| 45 | namespace N { |
| 46 | template<typename T> concept C7 = true; |
| 47 | } |
| 48 | using N::C7; |
| 49 | |
| 50 | template <bool word> concept C8 = integral_constant<bool, wor>::value; |
| 51 | // expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}} |
| 52 | // expected-note@-2{{'word' declared here}} |
| 53 | |
| 54 | template<typename T> concept bool C9 = true; |
| 55 | // expected-warning@-1{{ISO C++2a does not permit the 'bool' keyword after 'concept'}} |
| 56 | |
| 57 | template<> concept C10 = false; |
| 58 | // expected-error@-1{{concept template parameter list must have at least one parameter; explicit specialization of concepts is not allowed}} |
| 59 | |
| 60 | template<> concept C9<int> = false; |
| 61 | // expected-error@-1{{name defined in concept definition must be an identifier}} |
| 62 | |
| 63 | template<typename T> concept N::C11 = false; |
| 64 | // expected-error@-1{{name defined in concept definition must be an identifier}} |
| 65 | |
| 66 | class A { }; |
| 67 | // expected-note@-1{{'A' declared here}} |
| 68 | |
| 69 | template<typename T> concept A::C12 = false; |
| 70 | // expected-error@-1{{expected namespace name}} |
| 71 | |
| 72 | template<typename T> concept operator int = false; |
| 73 | // expected-error@-1{{name defined in concept definition must be an identifier}} |