comparison gcc/testsuite/g++.dg/cpp2a/concepts-p1141.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 }
2 // { dg-options "-std=c++2a" }
3
4 template<typename T>
5 concept Type = true;
6
7 template<typename T>
8 concept Bottom = false;
9
10 template<typename T>
11 concept Class = __is_class(T);
12
13 template<auto N>
14 concept Number = true;
15
16 template<template<typename> class T>
17 concept Template = true;
18
19 struct empty { };
20
21 Type x1 = 0; // { dg-error "expected 'auto'" }
22 Type auto x2 = 0;
23
24 Number x3 = 0; // { dg-error "does not constrain a type" }
25 Template x4 = 0; // { dg-error "does not constrain a type" }
26
27 Type const& x5 = 0; // { dg-error "expected 'auto'" }
28 const Type& x6 = 0; // { dg-error "expected 'auto'" }
29 Type auto const& x7 = 0;
30 const Type auto& x8 = 0;
31 Type const auto& x9 = 0; // { dg-error "expected 'auto'|two or more data types" }
32
33 template<Type T> // OK: T is a type parameter.
34 void f1(T);
35
36 template<Number N> // { dg-error "does not constrain a type" }
37 void f2();
38
39 template<Template X> // { dg-error "does not constrain a type" }
40 void f3();
41
42 template<Type auto N> // OK: N is a non-type parameter.
43 void f4() { }
44
45 template<Bottom auto N> // OK: but never usable.
46 void f5();
47
48 void driver() {
49 f4<0>();
50 f5<0>(); // { dg-error "no matching function for call | constraints not satisfied" }
51 }
52
53 Type f6() { return 0; } // { dg-error "expected 'auto'" }
54 static_assert(__is_same_as(decltype(f6), int()));
55
56 Type auto f7() { return 0; }
57 static_assert(__is_same_as(decltype(f7), int()));
58
59 Type f8() { return 0; } // { dg-error "expected 'auto'" }
60 auto f9() -> Type { return 0; } // { dg-error "expected 'auto'" }
61
62 Type f10() { } // { dg-error "expected 'auto'" }
63 auto f11() -> Type { } // { dg-error "expected" }
64
65 Number f12(); // { dg-error "does not constrain a type" }
66 auto f13() -> Number; // { dg-error "does not constrain a type" }
67
68 Template f14(); // { dg-error "does not constrain a type" }
69 auto f15() -> Template; // { dg-error "does not constrain a type" }
70
71 Type f16() { return 0; } // { dg-error "expected 'auto'" }
72 auto f17() -> Type { return 0; } // { dg-error "expected 'auto'" }
73
74 // Abbreviated function templates
75
76 void f18(Class x) { } // { dg-error "expected 'auto'" }
77 void f19(Class auto x) { }
78 void f20(Class auto x, Class auto y) { }
79
80 void driver_1()
81 {
82 f19(0); // { dg-error "" }
83 f19(empty{});
84 f20(0, empty{}); // { dg-error "" }
85 f20(empty{}, empty{});
86 }
87
88 // Abbreviated function redeclarations
89
90 // Functionally equivalent but not equivalent.
91 void f21(Class auto x);
92 template<Class T> void f21(T x);
93
94 void driver_2()
95 {
96 f21(empty{}); // { dg-error "call of overload | ambiguous" }
97 }
98