| 1 |
/************************************************************/ |
| 2 |
|
| 3 |
/* |
| 4 |
TEST_OUTPUT: |
| 5 |
--- |
| 6 |
fail_compilation/traits.d(100): Error: `getTargetInfo` key `"not_a_target_info"` not supported by this implementation |
| 7 |
fail_compilation/traits.d(101): Error: string expected as argument of __traits `getTargetInfo` instead of `100` |
| 8 |
fail_compilation/traits.d(102): Error: expected 1 arguments for `getTargetInfo` but had 2 |
| 9 |
fail_compilation/traits.d(103): Error: expected 1 arguments for `getTargetInfo` but had 0 |
| 10 |
fail_compilation/traits.d(200): Error: undefined identifier `imports.nonexistent` |
| 11 |
fail_compilation/traits.d(201): Error: undefined identifier `imports.nonexistent` |
| 12 |
fail_compilation/traits.d(202): Error: expected 1 arguments for `isPackage` but had 0 |
| 13 |
fail_compilation/traits.d(203): Error: expected 1 arguments for `isModule` but had 0 |
| 14 |
fail_compilation/traits.d(300): Error: in expression `__traits(allMembers, float)` `float` can't have members |
| 15 |
fail_compilation/traits.d(300): `float` must evaluate to either a module, a struct, an union, a class, an interface or a template instantiation |
| 16 |
fail_compilation/traits.d(306): Error: in expression `__traits(allMembers, TemplatedStruct)` struct `TemplatedStruct(T)` has no members |
| 17 |
fail_compilation/traits.d(306): `TemplatedStruct(T)` must evaluate to either a module, a struct, an union, a class, an interface or a template instantiation |
| 18 |
fail_compilation/traits.d(309): Error: in expression `__traits(derivedMembers, float)` `float` can't have members |
| 19 |
fail_compilation/traits.d(309): `float` must evaluate to either a module, a struct, an union, a class, an interface or a template instantiation |
| 20 |
fail_compilation/traits.d(316): Error: in expression `__traits(derivedMembers, TemplatedStruct)` struct `TemplatedStruct(T)` has no members |
| 21 |
fail_compilation/traits.d(316): `TemplatedStruct(T)` must evaluate to either a module, a struct, an union, a class, an interface or a template instantiation |
| 22 |
fail_compilation/traits.d(404): Error: function `traits.func1` circular reference in `__traits(GetCppNamespaces,...)` |
| 23 |
fail_compilation/traits.d(413): Error: function `traits.foo1.func1` circular reference in `__traits(GetCppNamespaces,...)` |
| 24 |
--- |
| 25 |
*/ |
| 26 |
|
| 27 |
#line 100 |
| 28 |
enum A1 = __traits(getTargetInfo, "not_a_target_info"); |
| 29 |
enum B1 = __traits(getTargetInfo, 100); |
| 30 |
enum C1 = __traits(getTargetInfo, "cppRuntimeLibrary", "bits"); |
| 31 |
enum D1 = __traits(getTargetInfo); |
| 32 |
|
| 33 |
#line 200 |
| 34 |
enum A2 = __traits(isPackage, imports.nonexistent); |
| 35 |
enum B2 = __traits(isModule, imports.nonexistent); |
| 36 |
enum C2 = __traits(isPackage); |
| 37 |
enum D2 = __traits(isModule); |
| 38 |
|
| 39 |
interface Interface {} |
| 40 |
struct TemplatedStruct(T) {} |
| 41 |
struct Struct {} |
| 42 |
union Union {} |
| 43 |
class Class {} |
| 44 |
|
| 45 |
#line 300 |
| 46 |
enum AM0 = __traits(allMembers, float); // compile error |
| 47 |
enum AM1 = __traits(allMembers, Struct); // no error |
| 48 |
enum AM2 = __traits(allMembers, Union); // no error |
| 49 |
enum AM3 = __traits(allMembers, Class); // no error |
| 50 |
enum AM4 = __traits(allMembers, Interface); // no error |
| 51 |
enum AM5 = __traits(allMembers, TemplatedStruct!float); // no error |
| 52 |
enum AM6 = __traits(allMembers, TemplatedStruct); // compile error |
| 53 |
enum AM7 = __traits(allMembers, mixin(__MODULE__)); // no error |
| 54 |
|
| 55 |
enum DM0 = __traits(derivedMembers, float); // compile error |
| 56 |
enum DM1 = __traits(derivedMembers, Struct); // no error |
| 57 |
enum DM2 = __traits(derivedMembers, Struct); // no error |
| 58 |
enum DM3 = __traits(derivedMembers, Union); // no error |
| 59 |
enum DM4 = __traits(derivedMembers, Class); // no error |
| 60 |
enum DM5 = __traits(derivedMembers, Interface); // no error |
| 61 |
enum DM6 = __traits(derivedMembers, TemplatedStruct!float); // no error |
| 62 |
enum DM7 = __traits(derivedMembers, TemplatedStruct); // compile error |
| 63 |
enum DM8 = __traits(derivedMembers, mixin(__MODULE__)); // no error |
| 64 |
|
| 65 |
#line 400 |
| 66 |
extern(C++, "bar") |
| 67 |
extern(C++, __traits(getCppNamespaces, func1)) void func () {} |
| 68 |
|
| 69 |
extern(C++, "foo") |
| 70 |
extern(C++, __traits(getCppNamespaces, func2)) void func1 () {} |
| 71 |
|
| 72 |
extern(C++, "foobar") |
| 73 |
extern(C++, __traits(getCppNamespaces, func)) void func2 () {} |
| 74 |
|
| 75 |
extern(C++, bar1) |
| 76 |
extern(C++, __traits(getCppNamespaces, foo1.func1)) void func () {} |
| 77 |
|
| 78 |
extern(C++, foo1) |
| 79 |
extern(C++, __traits(getCppNamespaces, foobar1.func2)) void func1 () {} |
| 80 |
|
| 81 |
extern(C++, foobar1) |
| 82 |
extern(C++, __traits(getCppNamespaces, bar1.func)) void func2 () {} |
| 83 |
|
| 84 |
/******************************************** |
| 85 |
https://issues.dlang.org/show_bug.cgi?id=21918 |
| 86 |
|
| 87 |
TEST_OUTPUT: |
| 88 |
--- |
| 89 |
fail_compilation/traits.d(501): Error: undefined identifier `T` |
| 90 |
fail_compilation/traits.d(502): while evaluating `pragma(msg, __traits(getParameterStorageClasses, yip, 0))` |
| 91 |
--- |
| 92 |
*/ |
| 93 |
#line 500 |
| 94 |
|
| 95 |
auto yip(int f) {return T[];} |
| 96 |
pragma(msg, __traits(getParameterStorageClasses, yip, 0)); |
| 97 |
|
| 98 |
|
| 99 |
/******************************************** |
| 100 |
TEST_OUTPUT: |
| 101 |
--- |
| 102 |
fail_compilation/traits.d(602): Error: expected 1 arguments for `hasCopyConstructor` but had 0 |
| 103 |
fail_compilation/traits.d(602): while evaluating `pragma(msg, __traits(hasCopyConstructor))` |
| 104 |
fail_compilation/traits.d(603): Error: type expected as second argument of __traits `hasCopyConstructor` instead of `S()` |
| 105 |
fail_compilation/traits.d(603): while evaluating `pragma(msg, __traits(hasCopyConstructor, S()))` |
| 106 |
fail_compilation/traits.d(604): Error: expected 1 arguments for `hasPostblit` but had 0 |
| 107 |
fail_compilation/traits.d(604): while evaluating `pragma(msg, __traits(hasPostblit))` |
| 108 |
fail_compilation/traits.d(605): Error: type expected as second argument of __traits `hasPostblit` instead of `S()` |
| 109 |
fail_compilation/traits.d(605): while evaluating `pragma(msg, __traits(hasPostblit, S()))` |
| 110 |
--- |
| 111 |
*/ |
| 112 |
#line 600 |
| 113 |
|
| 114 |
struct S { this (ref S rhs) {} } |
| 115 |
pragma(msg, __traits(hasCopyConstructor)); |
| 116 |
pragma(msg, __traits(hasCopyConstructor, S())); |
| 117 |
pragma(msg, __traits(hasPostblit)); |
| 118 |
pragma(msg, __traits(hasPostblit, S())); |
| 119 |
|
| 120 |
/******************************************** |
| 121 |
https://issues.dlang.org/show_bug.cgi?id=23178 |
| 122 |
|
| 123 |
TEST_OUTPUT: |
| 124 |
--- |
| 125 |
fail_compilation/traits.d(701): Error: alias `traits.a` cannot alias an expression `true` |
| 126 |
fail_compilation/traits.d(702): Error: alias `traits.b` cannot alias an expression `false` |
| 127 |
fail_compilation/traits.d(703): Error: alias `traits.c` cannot alias an expression `"Object"` |
| 128 |
fail_compilation/traits.d(704): while evaluating `pragma(msg, a)` |
| 129 |
--- |
| 130 |
*/ |
| 131 |
#line 700 |
| 132 |
|
| 133 |
alias a = __traits(compiles, 1); |
| 134 |
alias b = __traits(isIntegral, 1.1); |
| 135 |
alias c = __traits(identifier, Object); |
| 136 |
pragma(msg, a, b, c); |