1 /** 2 Tests for declarations that must be done at the end when they 3 haven't appeared yet (due to pointers to undeclared structs) 4 */ 5 module it.c.compile.collision; 6 7 import it; 8 9 @Tags("collision") 10 @("field of unknown struct pointer") 11 @safe unittest { 12 shouldCompile( 13 C( 14 q{ 15 typedef struct Foo { 16 struct Bar* bar; 17 } Foo; 18 } 19 ), 20 D( 21 q{ 22 Foo f; 23 f.bar = null; 24 } 25 ), 26 ); 27 } 28 29 @Tags("collision") 30 @("unknown struct pointer return") 31 @safe unittest { 32 shouldCompile( 33 C( 34 q{ 35 struct Foo* fun(int); 36 } 37 ), 38 D( 39 q{ 40 auto f = fun(42); 41 static assert(is(typeof(f) == Foo*)); 42 } 43 ), 44 ); 45 } 46 47 @Tags("collision") 48 @("unknown struct pointer param") 49 @safe unittest { 50 shouldCompile( 51 C( 52 q{ 53 int fun(struct Foo* foo); 54 } 55 ), 56 D( 57 q{ 58 Foo* foo; 59 int i = fun(foo); 60 } 61 ), 62 ); 63 } 64 65 66 @Tags("collision", "issue", "issue24") 67 @("Old issue 24") 68 @safe unittest { 69 shouldCompile( 70 C( 71 q{ 72 typedef struct _mailstream_low mailstream_low; 73 struct mailstream_cancel* mailstream_low_get_cancel(void); 74 struct _mailstream { 75 struct mailstream_cancel* idle; 76 }; 77 78 struct mailstream_low_driver { 79 void (*mailstream_cancel)(int); 80 struct mailstream_cancel* (*mailstream_get_cancel)(mailstream_low*); 81 }; 82 83 int mailstream_low_wait_idle(struct mailstream_cancel*); 84 85 struct _mailstream_low { 86 void* data; 87 struct mailstream_low_driver* driver; 88 int privacy; 89 char* identifier; 90 unsigned long timeout; 91 void* logger_context; 92 }; 93 } 94 ), 95 D( 96 q{ 97 // should just compile 98 } 99 ), 100 ); 101 } 102 103 @Tags("collision") 104 @("Undeclared struct pointer in function pointer field return type") 105 @safe unittest { 106 shouldCompile( 107 C( 108 q{ 109 struct Struct { 110 struct Foo* (*func)(void); 111 }; 112 } 113 ), 114 D( 115 q{ 116 Struct s; 117 Foo* foo = s.func(); 118 } 119 ), 120 ); 121 } 122 123 @Tags("collision") 124 @("Undeclared struct pointer in function pointer field param type") 125 @safe unittest { 126 shouldCompile( 127 C( 128 q{ 129 struct Struct { 130 void (*func)(struct Foo*, struct Bar*); 131 }; 132 } 133 ), 134 D( 135 q{ 136 Foo* foo; 137 Bar* bar; 138 Struct s; 139 s.func(foo, bar); 140 } 141 ), 142 ); 143 144 } 145 146 147 @Tags("collision") 148 @("foo and foo_ cause function foo to renamed as foo__") 149 @safe unittest { 150 shouldCompile( 151 C( 152 q{ 153 void foo(void); 154 // Struct causes the function to be named foo_ 155 struct Struct { struct foo* field; }; 156 struct foo_ { int dummy; }; 157 } 158 ), 159 D( 160 q{ 161 Struct s; 162 static assert(is(typeof(s.field) == foo*)); 163 foo_ f; 164 f.dummy = 42; 165 foo__(); 166 } 167 ), 168 ); 169 }