summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/concepts-ts6.C
blob: bf665aa6308998ee094148060c435f5e719ac444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// { dg-do compile { target c++2a } }
// { dg-additional-options "-fconcepts-ts" }

template<typename T, int N, typename... Xs> concept bool C1 = true;

template<template<typename> class X> concept bool C2 = true;

template<typename... Ts> concept bool C3 = true;

C1{A, B, ...C} struct S1 { };

C2{T} void f();

C2{...Ts} void g(); // { dg-error "cannot be introduced" }

C3{...Ts} struct S2 { };
C3{T, U, V} struct S3 { };
C3{...Ts, U} struct S4 { }; // { dg-error "cannot deduce template parameters" }

template<typename> struct X { };

void driver1() {
  S1<int, 0, char, bool, float> s1a;
  S1<0, 0, char, bool, float> s1b; // { dg-error "type/value mismatch" }

  f<X>();
  f<int>(); // { dg-error "no matching function for call" }

  S2<int> s2a;
  S2<char, signed char, unsigned char> s2b;
  S2<0> s2c; // { dg-error "type/value mismatch" }

  S3<int, int, int> s3a;
  S3<int, int> s3b; // { dg-error "wrong number of template arguments" }
}

template<typename... Args>
struct all_same;

template<typename T, typename U, typename... Args>
struct all_same<T, U, Args...>
{
  static constexpr bool value = __is_same_as(T, U) && all_same<U, Args...>::value;
};

template<typename T>
struct all_same<T>
{
  static constexpr bool value = true;
};

template<>
struct all_same<>
{
  static constexpr bool value = true;
};

template<typename... Ts>
concept AllSame = all_same<Ts...>::value;

AllSame{...Ts} struct S5 { };
AllSame{T, U} struct S6 { };

void driver2()
{
  S5<int, int> s5a;
  S5<int, int, int, int> s5b;
  S5<int, int, int, char> s5c; // { dg-error "template constraint failure" }
  S6<void, void> s6a;
  S6<void, int> s6c; // { dg-error "template constraint failure" }
  S6<void, void, void> s6b; // { dg-error "wrong number of template arguments" }
}