comparison gcc/testsuite/g++.dg/cpp2a/concepts2.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
3 template<typename T>
4 concept True = true;
5
6 template<typename T>
7 concept False = false;
8
9 template<typename T>
10 concept Int = __is_same_as(T, int);
11
12 static_assert(True<int>);
13 static_assert(!False<int>);
14 static_assert(False<int>); // { dg-error "static assertion failed" }
15
16 constexpr bool will_be_true() {
17 if (True<int>)
18 return true;
19 return false;
20 }
21
22 constexpr bool will_be_false() {
23 if (!False<int>)
24 return true;
25 return false;
26 }
27
28 static_assert(will_be_true());
29 static_assert(will_be_false());
30
31 template<typename T>
32 constexpr bool is_int() {
33 if (Int<T>)
34 return true;
35 return false;
36 }
37
38 static_assert(is_int<int>());
39 static_assert(is_int<void>()); // { dg-error "static assertion failed" }
40
41 template<typename T>
42 constexpr bool f1() {
43 if (Int<int>) // Note: always true.
44 return true;
45 return false;
46 }
47 static_assert(f1<int>());
48 static_assert(f1<void>());
49
50
51 template<typename T>
52 constexpr bool f2() {
53 if constexpr (Int<int>) // Note: always true.
54 return true;
55 return false;
56 }
57 static_assert(f2<int>());
58 static_assert(f2<void>());
59
60 template<typename T>
61 concept C = true;
62
63 int driver() {
64 bool c_int = (C<int>);
65 if((C<int>))
66 ;
67 return c_int;
68 }
69