]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/compilable/traits_getFunctionAttributes.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / traits_getFunctionAttributes.d
1
2 module traits_getFunctionAttributes;
3
4 void test_getFunctionAttributes()
5 {
6 alias tuple(T...) = T;
7
8 struct S
9 {
10 int noF() { return 0; }
11 int constF() const { return 0; }
12 int immutableF() immutable { return 0; }
13 int inoutF() inout { return 0; }
14 int sharedF() shared { return 0; }
15
16 int x;
17 ref int refF() return { return x; }
18 int propertyF() @property { return 0; }
19 int nothrowF() nothrow { return 0; }
20 int nogcF() @nogc { return 0; }
21
22 int systemF() @system { return 0; }
23 int trustedF() @trusted { return 0; }
24 int safeF() @safe { return 0; }
25
26 int pureF() pure { return 0; }
27
28 int liveF() @live { return 0; }
29 }
30
31 static assert(__traits(getFunctionAttributes, S.noF) == tuple!("@system"));
32 static assert(__traits(getFunctionAttributes, typeof(S.noF)) == tuple!("@system"));
33
34 static assert(__traits(getFunctionAttributes, S.constF) == tuple!("const", "@system"));
35 static assert(__traits(getFunctionAttributes, typeof(S.constF)) == tuple!("const", "@system"));
36
37 static assert(__traits(getFunctionAttributes, S.immutableF) == tuple!("immutable", "@system"));
38 static assert(__traits(getFunctionAttributes, typeof(S.immutableF)) == tuple!("immutable", "@system"));
39
40 static assert(__traits(getFunctionAttributes, S.inoutF) == tuple!("inout", "@system"));
41 static assert(__traits(getFunctionAttributes, typeof(S.inoutF)) == tuple!("inout", "@system"));
42
43 static assert(__traits(getFunctionAttributes, S.sharedF) == tuple!("shared", "@system"));
44 static assert(__traits(getFunctionAttributes, typeof(S.sharedF)) == tuple!("shared", "@system"));
45
46 static assert(__traits(getFunctionAttributes, S.refF) == tuple!("ref", "return", "@system"));
47 static assert(__traits(getFunctionAttributes, typeof(S.refF)) == tuple!("ref", "return", "@system"));
48
49 static assert(__traits(getFunctionAttributes, S.propertyF) == tuple!("@property", "@system"));
50 static assert(__traits(getFunctionAttributes, typeof(&S.propertyF)) == tuple!("@property", "@system"));
51
52 static assert(__traits(getFunctionAttributes, S.nothrowF) == tuple!("nothrow", "@system"));
53 static assert(__traits(getFunctionAttributes, typeof(S.nothrowF)) == tuple!("nothrow", "@system"));
54
55 static assert(__traits(getFunctionAttributes, S.nogcF) == tuple!("@nogc", "@system"));
56 static assert(__traits(getFunctionAttributes, typeof(S.nogcF)) == tuple!("@nogc", "@system"));
57
58 static assert(__traits(getFunctionAttributes, S.systemF) == tuple!("@system"));
59 static assert(__traits(getFunctionAttributes, typeof(S.systemF)) == tuple!("@system"));
60
61 static assert(__traits(getFunctionAttributes, S.trustedF) == tuple!("@trusted"));
62 static assert(__traits(getFunctionAttributes, typeof(S.trustedF)) == tuple!("@trusted"));
63
64 static assert(__traits(getFunctionAttributes, S.safeF) == tuple!("@safe"));
65 static assert(__traits(getFunctionAttributes, typeof(S.safeF)) == tuple!("@safe"));
66
67 static assert(__traits(getFunctionAttributes, S.pureF) == tuple!("pure", "@system"));
68 static assert(__traits(getFunctionAttributes, typeof(S.pureF)) == tuple!("pure", "@system"));
69
70 static assert(__traits(getFunctionAttributes, S.liveF) == tuple!("@live", "@system"));
71 static assert(__traits(getFunctionAttributes, typeof(S.liveF)) == tuple!("@live", "@system"));
72
73 int pure_nothrow() nothrow pure { return 0; }
74 static ref int static_ref_property() @property { return *(new int); }
75 ref int ref_property() @property { return *(new int); }
76 void safe_nothrow() @safe nothrow { }
77 void live_nothrow() nothrow @live { }
78
79 static assert(__traits(getFunctionAttributes, pure_nothrow) == tuple!("pure", "nothrow", "@nogc", "@safe"));
80 static assert(__traits(getFunctionAttributes, typeof(pure_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@safe"));
81
82 static assert(__traits(getFunctionAttributes, static_ref_property) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));
83 static assert(__traits(getFunctionAttributes, typeof(&static_ref_property)) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));
84
85 static assert(__traits(getFunctionAttributes, ref_property) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));
86 static assert(__traits(getFunctionAttributes, typeof(&ref_property)) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));
87
88 static assert(__traits(getFunctionAttributes, safe_nothrow) == tuple!("pure", "nothrow", "@nogc", "@safe"));
89 static assert(__traits(getFunctionAttributes, typeof(safe_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@safe"));
90
91 static assert(__traits(getFunctionAttributes, live_nothrow) == tuple!("pure", "nothrow", "@nogc", "@live", "@safe"));
92 static assert(__traits(getFunctionAttributes, typeof(live_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@live", "@safe"));
93
94 struct S2
95 {
96 int pure_const() const pure { return 0; }
97 int pure_sharedconst() const shared pure { return 0; }
98 }
99
100 static assert(__traits(getFunctionAttributes, S2.pure_const) == tuple!("const", "pure", "@system"));
101 static assert(__traits(getFunctionAttributes, typeof(S2.pure_const)) == tuple!("const", "pure", "@system"));
102
103 static assert(__traits(getFunctionAttributes, S2.pure_sharedconst) == tuple!("const", "shared", "pure", "@system"));
104 static assert(__traits(getFunctionAttributes, typeof(S2.pure_sharedconst)) == tuple!("const", "shared", "pure", "@system"));
105
106 static assert(__traits(getFunctionAttributes, (int a) { }) == tuple!("pure", "nothrow", "@nogc", "@safe"));
107 static assert(__traits(getFunctionAttributes, typeof((int a) { })) == tuple!("pure", "nothrow", "@nogc", "@safe"));
108
109 auto safeDel = delegate() @safe { };
110 static assert(__traits(getFunctionAttributes, safeDel) == tuple!("pure", "nothrow", "@nogc", "@safe"));
111 static assert(__traits(getFunctionAttributes, typeof(safeDel)) == tuple!("pure", "nothrow", "@nogc", "@safe"));
112
113 auto trustedDel = delegate() @trusted { };
114 static assert(__traits(getFunctionAttributes, trustedDel) == tuple!("pure", "nothrow", "@nogc", "@trusted"));
115 static assert(__traits(getFunctionAttributes, typeof(trustedDel)) == tuple!("pure", "nothrow", "@nogc", "@trusted"));
116
117 auto systemDel = delegate() @system { };
118 static assert(__traits(getFunctionAttributes, systemDel) == tuple!("pure", "nothrow", "@nogc", "@system"));
119 static assert(__traits(getFunctionAttributes, typeof(systemDel)) == tuple!("pure", "nothrow", "@nogc", "@system"));
120 }