comparison gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // { dg-do compile { target c++2a } }
2 // { dg-additional-options "-fconcepts-ts" }
3
4 template<typename T, int N, typename... Xs> concept bool C1 = true;
5
6 template<template<typename> class X> concept bool C2 = true;
7
8 template<typename... Ts> concept bool C3 = true;
9
10 C1{A, B, ...C} struct S1 { };
11
12 C2{T} void f();
13
14 C2{...Ts} void g(); // { dg-error "cannot be introduced" }
15
16 C3{...Ts} struct S2 { };
17 C3{T, U, V} struct S3 { };
18 C3{...Ts, U} struct S4 { }; // { dg-error "cannot deduce template parameters" }
19
20 template<typename> struct X { };
21
22 void driver1() {
23 S1<int, 0, char, bool, float> s1a;
24 S1<0, 0, char, bool, float> s1b; // { dg-error "type/value mismatch" }
25
26 f<X>();
27 f<int>(); // { dg-error "no matching function for call" }
28
29 S2<int> s2a;
30 S2<char, signed char, unsigned char> s2b;
31 S2<0> s2c; // { dg-error "type/value mismatch" }
32
33 S3<int, int, int> s3a;
34 S3<int, int> s3b; // { dg-error "wrong number of template arguments" }
35 }
36
37 template<typename... Args>
38 struct all_same;
39
40 template<typename T, typename U, typename... Args>
41 struct all_same<T, U, Args...>
42 {
43 static constexpr bool value = __is_same_as(T, U) && all_same<U, Args...>::value;
44 };
45
46 template<typename T>
47 struct all_same<T>
48 {
49 static constexpr bool value = true;
50 };
51
52 template<>
53 struct all_same<>
54 {
55 static constexpr bool value = true;
56 };
57
58 template<typename... Ts>
59 concept AllSame = all_same<Ts...>::value;
60
61 AllSame{...Ts} struct S5 { };
62 AllSame{T, U} struct S6 { };
63
64 void driver2()
65 {
66 S5<int, int> s5a;
67 S5<int, int, int, int> s5b;
68 S5<int, int, int, char> s5c; // { dg-error "template constraint failure" }
69 S6<void, void> s6a;
70 S6<void, int> s6c; // { dg-error "template constraint failure" }
71 S6<void, void, void> s6b; // { dg-error "wrong number of template arguments" }
72 }