Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1 | // Clear and create directories |
| 2 | // RUN: rm -rf %t |
| 3 | // RUN: mkdir %t |
| 4 | // RUN: mkdir %t/cache |
| 5 | // RUN: mkdir %t/Inputs |
| 6 | |
| 7 | // Build first header file |
| 8 | // RUN: echo "#define FIRST" >> %t/Inputs/first.h |
| 9 | // RUN: cat %s >> %t/Inputs/first.h |
| 10 | |
| 11 | // Build second header file |
| 12 | // RUN: echo "#define SECOND" >> %t/Inputs/second.h |
| 13 | // RUN: cat %s >> %t/Inputs/second.h |
| 14 | |
| 15 | // Build module map file |
| 16 | // RUN: echo "module FirstModule {" >> %t/Inputs/module.map |
| 17 | // RUN: echo " header \"first.h\"" >> %t/Inputs/module.map |
| 18 | // RUN: echo "}" >> %t/Inputs/module.map |
| 19 | // RUN: echo "module SecondModule {" >> %t/Inputs/module.map |
| 20 | // RUN: echo " header \"second.h\"" >> %t/Inputs/module.map |
| 21 | // RUN: echo "}" >> %t/Inputs/module.map |
| 22 | |
| 23 | // Run test |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 24 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 25 | |
| 26 | #if !defined(FIRST) && !defined(SECOND) |
| 27 | #include "first.h" |
| 28 | #include "second.h" |
| 29 | #endif |
| 30 | |
| 31 | namespace AccessSpecifiers { |
| 32 | #if defined(FIRST) |
| 33 | struct S1 { |
| 34 | }; |
| 35 | #elif defined(SECOND) |
| 36 | struct S1 { |
| 37 | private: |
| 38 | }; |
| 39 | #else |
| 40 | S1 s1; |
| 41 | // expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 42 | // expected-note@first.h:* {{but in 'FirstModule' found end of class}} |
| 43 | #endif |
| 44 | |
| 45 | #if defined(FIRST) |
| 46 | struct S2 { |
| 47 | public: |
| 48 | }; |
| 49 | #elif defined(SECOND) |
| 50 | struct S2 { |
| 51 | protected: |
| 52 | }; |
| 53 | #else |
| 54 | S2 s2; |
| 55 | // expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}} |
| 56 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 57 | #endif |
| 58 | } // namespace AccessSpecifiers |
| 59 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 60 | namespace StaticAssert { |
| 61 | #if defined(FIRST) |
| 62 | struct S1 { |
| 63 | static_assert(1 == 1, "First"); |
| 64 | }; |
| 65 | #elif defined(SECOND) |
| 66 | struct S1 { |
| 67 | static_assert(1 == 1, "Second"); |
| 68 | }; |
| 69 | #else |
| 70 | S1 s1; |
| 71 | // expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}} |
| 72 | // expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}} |
| 73 | #endif |
| 74 | |
| 75 | #if defined(FIRST) |
| 76 | struct S2 { |
| 77 | static_assert(2 == 2, "Message"); |
| 78 | }; |
| 79 | #elif defined(SECOND) |
| 80 | struct S2 { |
| 81 | static_assert(2 == 2); |
| 82 | }; |
| 83 | #else |
| 84 | S2 s2; |
| 85 | // expected-error@second.h:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}} |
| 86 | // expected-note@first.h:* {{but in 'FirstModule' found static assert with message}} |
| 87 | #endif |
| 88 | |
| 89 | #if defined(FIRST) |
| 90 | struct S3 { |
| 91 | static_assert(3 == 3, "Message"); |
| 92 | }; |
| 93 | #elif defined(SECOND) |
| 94 | struct S3 { |
| 95 | static_assert(3 != 4, "Message"); |
| 96 | }; |
| 97 | #else |
| 98 | S3 s3; |
| 99 | // expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}} |
| 100 | // expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}} |
| 101 | #endif |
| 102 | |
| 103 | #if defined(FIRST) |
| 104 | struct S4 { |
| 105 | static_assert(4 == 4, "Message"); |
| 106 | }; |
| 107 | #elif defined(SECOND) |
| 108 | struct S4 { |
| 109 | public: |
| 110 | }; |
| 111 | #else |
| 112 | S4 s4; |
| 113 | // expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 114 | // expected-note@first.h:* {{but in 'FirstModule' found static assert}} |
| 115 | #endif |
| 116 | } |
| 117 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 118 | namespace Field { |
| 119 | #if defined(FIRST) |
| 120 | struct S1 { |
| 121 | int x; |
| 122 | private: |
| 123 | int y; |
| 124 | }; |
| 125 | #elif defined(SECOND) |
| 126 | struct S1 { |
| 127 | int x; |
| 128 | int y; |
| 129 | }; |
| 130 | #else |
| 131 | S1 s1; |
| 132 | // expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} |
| 133 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 134 | #endif |
| 135 | |
| 136 | #if defined(FIRST) |
| 137 | struct S2 { |
| 138 | int x; |
| 139 | int y; |
| 140 | }; |
| 141 | #elif defined(SECOND) |
| 142 | struct S2 { |
| 143 | int y; |
| 144 | int x; |
| 145 | }; |
| 146 | #else |
| 147 | S2 s2; |
| 148 | // expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} |
| 149 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}} |
| 150 | #endif |
Richard Trieu | bcaaf96 | 2017-02-23 03:25:57 +0000 | [diff] [blame] | 151 | |
| 152 | #if defined(FIRST) |
| 153 | struct S3 { |
| 154 | double x; |
| 155 | }; |
| 156 | #elif defined(SECOND) |
| 157 | struct S3 { |
| 158 | int x; |
| 159 | }; |
| 160 | #else |
| 161 | S3 s3; |
| 162 | // expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}} |
| 163 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 164 | #endif |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 165 | |
| 166 | #if defined(FIRST) |
| 167 | typedef int A; |
| 168 | struct S4 { |
| 169 | A x; |
| 170 | }; |
| 171 | |
| 172 | struct S5 { |
| 173 | A x; |
| 174 | }; |
| 175 | #elif defined(SECOND) |
| 176 | typedef int B; |
| 177 | struct S4 { |
| 178 | B x; |
| 179 | }; |
| 180 | |
| 181 | struct S5 { |
| 182 | int x; |
| 183 | }; |
| 184 | #else |
| 185 | S4 s4; |
Alex Lorenz | 76377dc | 2017-03-10 15:04:58 +0000 | [diff] [blame] | 186 | // expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'Field::B' (aka 'int')}} |
| 187 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}} |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 188 | |
| 189 | S5 s5; |
| 190 | // expected-error@second.h:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}} |
Alex Lorenz | 76377dc | 2017-03-10 15:04:58 +0000 | [diff] [blame] | 191 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}} |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 192 | #endif |
| 193 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 194 | #if defined(FIRST) |
| 195 | struct S6 { |
| 196 | unsigned x; |
| 197 | }; |
| 198 | #elif defined(SECOND) |
| 199 | struct S6 { |
| 200 | unsigned x : 1; |
| 201 | }; |
| 202 | #else |
| 203 | S6 s6; |
| 204 | // expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}} |
| 205 | // expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}} |
| 206 | #endif |
| 207 | |
| 208 | #if defined(FIRST) |
| 209 | struct S7 { |
| 210 | unsigned x : 2; |
| 211 | }; |
| 212 | #elif defined(SECOND) |
| 213 | struct S7 { |
| 214 | unsigned x : 1; |
| 215 | }; |
| 216 | #else |
| 217 | S7 s7; |
| 218 | // expected-error@second.h:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}} |
| 219 | // expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}} |
| 220 | #endif |
| 221 | |
| 222 | #if defined(FIRST) |
| 223 | struct S8 { |
| 224 | unsigned x : 2; |
| 225 | }; |
| 226 | #elif defined(SECOND) |
| 227 | struct S8 { |
| 228 | unsigned x : 1 + 1; |
| 229 | }; |
| 230 | #else |
| 231 | S8 s8; |
| 232 | // expected-error@second.h:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}} |
| 233 | // expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}} |
| 234 | #endif |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 235 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 236 | #if defined(FIRST) |
| 237 | struct S9 { |
| 238 | mutable int x; |
| 239 | }; |
| 240 | #elif defined(SECOND) |
| 241 | struct S9 { |
| 242 | int x; |
| 243 | }; |
| 244 | #else |
| 245 | S9 s9; |
| 246 | // expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}} |
| 247 | // expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}} |
| 248 | #endif |
| 249 | |
| 250 | #if defined(FIRST) |
| 251 | struct S10 { |
| 252 | unsigned x = 5; |
| 253 | }; |
| 254 | #elif defined(SECOND) |
| 255 | struct S10 { |
| 256 | unsigned x; |
| 257 | }; |
| 258 | #else |
| 259 | S10 s10; |
| 260 | // expected-error@second.h:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initalizer}} |
| 261 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}} |
| 262 | #endif |
| 263 | |
| 264 | #if defined(FIRST) |
| 265 | struct S11 { |
| 266 | unsigned x = 5; |
| 267 | }; |
| 268 | #elif defined(SECOND) |
| 269 | struct S11 { |
| 270 | unsigned x = 7; |
| 271 | }; |
| 272 | #else |
| 273 | S11 s11; |
| 274 | // expected-error@second.h:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}} |
| 275 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}} |
| 276 | #endif |
| 277 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 278 | #if defined(FIRST) |
| 279 | struct S12 { |
| 280 | unsigned x[5]; |
| 281 | }; |
| 282 | #elif defined(SECOND) |
| 283 | struct S12 { |
| 284 | unsigned x[7]; |
| 285 | }; |
| 286 | #else |
| 287 | S12 s12; |
| 288 | // expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}} |
| 289 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 290 | #endif |
| 291 | |
| 292 | #if defined(FIRST) |
| 293 | struct S13 { |
| 294 | unsigned x[7]; |
| 295 | }; |
| 296 | #elif defined(SECOND) |
| 297 | struct S13 { |
| 298 | double x[7]; |
| 299 | }; |
| 300 | #else |
| 301 | S13 s13; |
| 302 | // expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}} |
| 303 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 304 | #endif |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 305 | } // namespace Field |
| 306 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 307 | namespace Method { |
| 308 | #if defined(FIRST) |
| 309 | struct S1 { |
| 310 | void A() {} |
| 311 | }; |
| 312 | #elif defined(SECOND) |
| 313 | struct S1 { |
| 314 | private: |
| 315 | void A() {} |
| 316 | }; |
| 317 | #else |
| 318 | S1 s1; |
| 319 | // expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 320 | // expected-note@first.h:* {{but in 'FirstModule' found method}} |
| 321 | #endif |
| 322 | |
| 323 | #if defined(FIRST) |
| 324 | struct S2 { |
| 325 | void A() {} |
| 326 | void B() {} |
| 327 | }; |
| 328 | #elif defined(SECOND) |
| 329 | struct S2 { |
| 330 | void B() {} |
| 331 | void A() {} |
| 332 | }; |
| 333 | #else |
| 334 | S2 s2; |
| 335 | // expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}} |
| 336 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A'}} |
| 337 | #endif |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 338 | |
| 339 | #if defined(FIRST) |
| 340 | struct S3 { |
| 341 | static void A() {} |
Richard Trieu | f4b54fe | 2017-03-04 03:04:15 +0000 | [diff] [blame] | 342 | void A(int) {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 343 | }; |
| 344 | #elif defined(SECOND) |
| 345 | struct S3 { |
Richard Trieu | f4b54fe | 2017-03-04 03:04:15 +0000 | [diff] [blame] | 346 | void A(int) {} |
| 347 | static void A() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 348 | }; |
| 349 | #else |
| 350 | S3 s3; |
| 351 | // expected-error@second.h:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}} |
| 352 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}} |
| 353 | #endif |
| 354 | |
| 355 | #if defined(FIRST) |
| 356 | struct S4 { |
| 357 | virtual void A() {} |
| 358 | void B() {} |
| 359 | }; |
| 360 | #elif defined(SECOND) |
| 361 | struct S4 { |
| 362 | void A() {} |
| 363 | virtual void B() {} |
| 364 | }; |
| 365 | #else |
| 366 | S4 s4; |
| 367 | // expected-error@second.h:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}} |
| 368 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}} |
| 369 | #endif |
| 370 | |
| 371 | #if defined(FIRST) |
| 372 | struct S5 { |
| 373 | virtual void A() = 0; |
| 374 | virtual void B() {}; |
| 375 | }; |
| 376 | #elif defined(SECOND) |
| 377 | struct S5 { |
| 378 | virtual void A() {} |
| 379 | virtual void B() = 0; |
| 380 | }; |
| 381 | #else |
| 382 | S5 *s5; |
| 383 | // expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}} |
| 384 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}} |
| 385 | #endif |
| 386 | |
| 387 | #if defined(FIRST) |
| 388 | struct S6 { |
| 389 | inline void A() {} |
| 390 | }; |
| 391 | #elif defined(SECOND) |
| 392 | struct S6 { |
| 393 | void A() {} |
| 394 | }; |
| 395 | #else |
| 396 | S6 s6; |
| 397 | // expected-error@second.h:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}} |
| 398 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}} |
| 399 | #endif |
| 400 | |
| 401 | #if defined(FIRST) |
| 402 | struct S7 { |
| 403 | void A() volatile {} |
| 404 | void A() {} |
| 405 | }; |
| 406 | #elif defined(SECOND) |
| 407 | struct S7 { |
| 408 | void A() {} |
| 409 | void A() volatile {} |
| 410 | }; |
| 411 | #else |
| 412 | S7 s7; |
| 413 | // expected-error@second.h:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}} |
| 414 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}} |
| 415 | #endif |
| 416 | |
| 417 | #if defined(FIRST) |
| 418 | struct S8 { |
| 419 | void A() const {} |
| 420 | void A() {} |
| 421 | }; |
| 422 | #elif defined(SECOND) |
| 423 | struct S8 { |
| 424 | void A() {} |
| 425 | void A() const {} |
| 426 | }; |
| 427 | #else |
| 428 | S8 s8; |
| 429 | // expected-error@second.h:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}} |
| 430 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}} |
| 431 | #endif |
| 432 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 433 | #if defined(FIRST) |
| 434 | struct S9 { |
| 435 | void A(int x) {} |
| 436 | void A(int x, int y) {} |
| 437 | }; |
| 438 | #elif defined(SECOND) |
| 439 | struct S9 { |
| 440 | void A(int x, int y) {} |
| 441 | void A(int x) {} |
| 442 | }; |
| 443 | #else |
| 444 | S9 s9; |
| 445 | // expected-error@second.h:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}} |
| 446 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}} |
| 447 | #endif |
| 448 | |
| 449 | #if defined(FIRST) |
| 450 | struct S10 { |
| 451 | void A(int x) {} |
| 452 | void A(float x) {} |
| 453 | }; |
| 454 | #elif defined(SECOND) |
| 455 | struct S10 { |
| 456 | void A(float x) {} |
| 457 | void A(int x) {} |
| 458 | }; |
| 459 | #else |
| 460 | S10 s10; |
| 461 | // expected-error@second.h:* {{'Method::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'float'}} |
| 462 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}} |
| 463 | #endif |
| 464 | |
| 465 | #if defined(FIRST) |
| 466 | struct S11 { |
| 467 | void A(int x) {} |
| 468 | }; |
| 469 | #elif defined(SECOND) |
| 470 | struct S11 { |
| 471 | void A(int y) {} |
| 472 | }; |
| 473 | #else |
| 474 | S11 s11; |
| 475 | // expected-error@second.h:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}} |
| 476 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}} |
| 477 | #endif |
| 478 | |
| 479 | #if defined(FIRST) |
| 480 | struct S12 { |
| 481 | void A(int x) {} |
| 482 | }; |
| 483 | #elif defined(SECOND) |
| 484 | struct S12 { |
| 485 | void A(int x = 1) {} |
| 486 | }; |
| 487 | #else |
| 488 | S12 s12; |
| 489 | // TODO: This should produce an error. |
| 490 | #endif |
| 491 | |
| 492 | #if defined(FIRST) |
| 493 | struct S13 { |
| 494 | void A(int x = 1 + 0) {} |
| 495 | }; |
| 496 | #elif defined(SECOND) |
| 497 | struct S13 { |
| 498 | void A(int x = 1) {} |
| 499 | }; |
| 500 | #else |
| 501 | S13 s13; |
| 502 | // TODO: This should produce an error. |
| 503 | #endif |
| 504 | |
| 505 | #if defined(FIRST) |
| 506 | struct S14 { |
| 507 | void A(int x[2]) {} |
| 508 | }; |
| 509 | #elif defined(SECOND) |
| 510 | struct S14 { |
| 511 | void A(int x[3]) {} |
| 512 | }; |
| 513 | #else |
| 514 | S14 s14; |
| 515 | // expected-error@second.h:* {{'Method::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [3]'}} |
| 516 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}} |
| 517 | #endif |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 518 | } // namespace Method |
| 519 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 520 | // Naive parsing of AST can lead to cycles in processing. Ensure |
| 521 | // self-references don't trigger an endless cycles of AST node processing. |
| 522 | namespace SelfReference { |
| 523 | #if defined(FIRST) |
| 524 | template <template <int> class T> class Wrapper {}; |
| 525 | |
| 526 | template <int N> class S { |
| 527 | S(Wrapper<::SelfReference::S> &Ref) {} |
| 528 | }; |
| 529 | |
| 530 | struct Xx { |
| 531 | struct Yy { |
| 532 | }; |
| 533 | }; |
| 534 | |
| 535 | Xx::Xx::Xx::Yy yy; |
| 536 | |
| 537 | namespace NNS { |
| 538 | template <typename> struct Foo; |
| 539 | template <template <class> class T = NNS::Foo> |
| 540 | struct NestedNamespaceSpecifier {}; |
| 541 | } |
| 542 | #endif |
| 543 | } // namespace SelfReference |
| 544 | |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 545 | namespace TypeDef { |
| 546 | #if defined(FIRST) |
| 547 | struct S1 { |
| 548 | typedef int a; |
| 549 | }; |
| 550 | #elif defined(SECOND) |
| 551 | struct S1 { |
| 552 | typedef double a; |
| 553 | }; |
| 554 | #else |
| 555 | S1 s1; |
| 556 | // expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}} |
| 557 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 558 | #endif |
| 559 | |
| 560 | #if defined(FIRST) |
| 561 | struct S2 { |
| 562 | typedef int a; |
| 563 | }; |
| 564 | #elif defined(SECOND) |
| 565 | struct S2 { |
| 566 | typedef int b; |
| 567 | }; |
| 568 | #else |
| 569 | S2 s2; |
| 570 | // expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}} |
| 571 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 572 | #endif |
| 573 | |
| 574 | #if defined(FIRST) |
| 575 | typedef int T; |
| 576 | struct S3 { |
| 577 | typedef T a; |
| 578 | }; |
| 579 | #elif defined(SECOND) |
| 580 | typedef double T; |
| 581 | struct S3 { |
| 582 | typedef T a; |
| 583 | }; |
| 584 | #else |
| 585 | S3 s3; |
| 586 | // expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}} |
| 587 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 588 | #endif |
| 589 | } // namespace TypeDef |
| 590 | |
| 591 | namespace Using { |
| 592 | #if defined(FIRST) |
| 593 | struct S1 { |
| 594 | using a = int; |
| 595 | }; |
| 596 | #elif defined(SECOND) |
| 597 | struct S1 { |
| 598 | using a = double; |
| 599 | }; |
| 600 | #else |
| 601 | S1 s1; |
| 602 | // expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}} |
| 603 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 604 | #endif |
| 605 | |
| 606 | #if defined(FIRST) |
| 607 | struct S2 { |
| 608 | using a = int; |
| 609 | }; |
| 610 | #elif defined(SECOND) |
| 611 | struct S2 { |
| 612 | using b = int; |
| 613 | }; |
| 614 | #else |
| 615 | S2 s2; |
| 616 | // expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}} |
| 617 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 618 | #endif |
| 619 | |
| 620 | #if defined(FIRST) |
| 621 | typedef int T; |
| 622 | struct S3 { |
| 623 | using a = T; |
| 624 | }; |
| 625 | #elif defined(SECOND) |
| 626 | typedef double T; |
| 627 | struct S3 { |
| 628 | using a = T; |
| 629 | }; |
| 630 | #else |
| 631 | S3 s3; |
| 632 | // expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}} |
| 633 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 634 | #endif |
| 635 | } // namespace Using |
| 636 | |
Richard Trieu | 58bb7bd | 2017-05-17 02:29:02 +0000 | [diff] [blame] | 637 | namespace RecordType { |
| 638 | #if defined(FIRST) |
| 639 | struct B1 {}; |
| 640 | struct S1 { |
| 641 | B1 x; |
| 642 | }; |
| 643 | #elif defined(SECOND) |
| 644 | struct A1 {}; |
| 645 | struct S1 { |
| 646 | A1 x; |
| 647 | }; |
| 648 | #else |
| 649 | S1 s1; |
| 650 | // expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}} |
| 651 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 652 | #endif |
| 653 | } |
| 654 | |
| 655 | namespace DependentType { |
| 656 | #if defined(FIRST) |
| 657 | template <class T> |
| 658 | class S1 { |
| 659 | typename T::typeA x; |
| 660 | }; |
| 661 | #elif defined(SECOND) |
| 662 | template <class T> |
| 663 | class S1 { |
| 664 | typename T::typeB x; |
| 665 | }; |
| 666 | #else |
| 667 | template<class T> |
| 668 | using U1 = S1<T>; |
| 669 | // expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}} |
| 670 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 671 | #endif |
| 672 | } |
| 673 | |
| 674 | namespace ElaboratedType { |
| 675 | #if defined(FIRST) |
| 676 | namespace N1 { using type = double; } |
| 677 | struct S1 { |
| 678 | N1::type x; |
| 679 | }; |
| 680 | #elif defined(SECOND) |
| 681 | namespace N1 { using type = int; } |
| 682 | struct S1 { |
| 683 | N1::type x; |
| 684 | }; |
| 685 | #else |
| 686 | S1 s1; |
| 687 | // expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}} |
| 688 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 689 | #endif |
| 690 | } |
| 691 | |
| 692 | namespace Enum { |
| 693 | #if defined(FIRST) |
| 694 | enum A1 {}; |
| 695 | struct S1 { |
| 696 | A1 x; |
| 697 | }; |
| 698 | #elif defined(SECOND) |
| 699 | enum A2 {}; |
| 700 | struct S1 { |
| 701 | A2 x; |
| 702 | }; |
| 703 | #else |
| 704 | S1 s1; |
| 705 | // expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}} |
| 706 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 707 | #endif |
| 708 | } |
Hans Wennborg | 2270776 | 2017-04-12 16:40:26 +0000 | [diff] [blame] | 709 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 710 | // Interesting cases that should not cause errors. struct S should not error |
| 711 | // while struct T should error at the access specifier mismatch at the end. |
| 712 | namespace AllDecls { |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 713 | #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \ |
| 714 | typedef int INT; \ |
| 715 | struct NAME { \ |
| 716 | public: \ |
| 717 | private: \ |
| 718 | protected: \ |
| 719 | static_assert(1 == 1, "Message"); \ |
| 720 | static_assert(2 == 2); \ |
| 721 | \ |
| 722 | int x; \ |
| 723 | double y; \ |
| 724 | \ |
| 725 | INT z; \ |
| 726 | \ |
| 727 | unsigned a : 1; \ |
| 728 | unsigned b : 2 * 2 + 5 / 2; \ |
| 729 | \ |
| 730 | mutable int c = sizeof(x + y); \ |
| 731 | \ |
| 732 | void method() {} \ |
| 733 | static void static_method() {} \ |
| 734 | virtual void virtual_method() {} \ |
| 735 | virtual void pure_virtual_method() = 0; \ |
| 736 | inline void inline_method() {} \ |
| 737 | void volatile_method() volatile {} \ |
| 738 | void const_method() const {} \ |
| 739 | \ |
| 740 | typedef int typedef_int; \ |
| 741 | using using_int = int; \ |
| 742 | \ |
| 743 | void method_one_arg(int x) {} \ |
| 744 | void method_one_arg_default_argument(int x = 5 + 5) {} \ |
| 745 | void method_decayed_type(int x[5]) {} \ |
| 746 | \ |
| 747 | int constant_arr[5]; \ |
| 748 | \ |
| 749 | ACCESS: \ |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 750 | }; |
| 751 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 752 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 753 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 754 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 755 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 756 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 757 | S *s; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 758 | #endif |
| 759 | |
| 760 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 761 | CREATE_ALL_DECL_STRUCT(T, private) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 762 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 763 | CREATE_ALL_DECL_STRUCT(T, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 764 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 765 | T *t; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 766 | // expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 767 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 768 | #endif |
| 769 | } |
| 770 | |
| 771 | namespace FriendFunction { |
| 772 | #if defined(FIRST) |
| 773 | void F(int = 0); |
| 774 | struct S { friend void F(int); }; |
| 775 | #elif defined(SECOND) |
| 776 | void F(int); |
| 777 | struct S { friend void F(int); }; |
| 778 | #else |
| 779 | S s; |
| 780 | #endif |
| 781 | |
| 782 | #if defined(FIRST) |
| 783 | void G(int = 0); |
| 784 | struct T { |
| 785 | friend void G(int); |
| 786 | |
| 787 | private: |
| 788 | }; |
| 789 | #elif defined(SECOND) |
| 790 | void G(int); |
| 791 | struct T { |
| 792 | friend void G(int); |
| 793 | |
| 794 | public: |
| 795 | }; |
| 796 | #else |
| 797 | T t; |
| 798 | // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 799 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 800 | #endif |
| 801 | } // namespace FriendFunction |
| 802 | |
| 803 | namespace ImplicitDecl { |
| 804 | #if defined(FIRST) |
| 805 | struct S { }; |
| 806 | void S_Constructors() { |
| 807 | // Trigger creation of implicit contructors |
| 808 | S foo; |
| 809 | S bar = foo; |
| 810 | S baz(bar); |
| 811 | } |
| 812 | #elif defined(SECOND) |
| 813 | struct S { }; |
| 814 | #else |
| 815 | S s; |
| 816 | #endif |
| 817 | |
| 818 | #if defined(FIRST) |
| 819 | struct T { |
| 820 | private: |
| 821 | }; |
| 822 | void T_Constructors() { |
| 823 | // Trigger creation of implicit contructors |
| 824 | T foo; |
| 825 | T bar = foo; |
| 826 | T baz(bar); |
| 827 | } |
| 828 | #elif defined(SECOND) |
| 829 | struct T { |
| 830 | public: |
| 831 | }; |
| 832 | #else |
| 833 | T t; |
| 834 | // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} |
| 835 | // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}} |
| 836 | #endif |
| 837 | |
| 838 | } // namespace ImplicitDelc |
| 839 | |
| 840 | namespace TemplatedClass { |
| 841 | #if defined(FIRST) |
| 842 | template <class> |
| 843 | struct S {}; |
| 844 | #elif defined(SECOND) |
| 845 | template <class> |
| 846 | struct S {}; |
| 847 | #else |
| 848 | S<int> s; |
| 849 | #endif |
| 850 | |
| 851 | #if defined(FIRST) |
| 852 | template <class> |
| 853 | struct T { |
| 854 | private: |
| 855 | }; |
| 856 | #elif defined(SECOND) |
| 857 | template <class> |
| 858 | struct T { |
| 859 | public: |
| 860 | }; |
| 861 | #else |
| 862 | T<int> t; |
| 863 | // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 864 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 865 | #endif |
| 866 | } // namespace TemplatedClass |
| 867 | |
| 868 | namespace TemplateClassWithField { |
| 869 | #if defined(FIRST) |
| 870 | template <class A> |
| 871 | struct S { |
| 872 | A a; |
| 873 | }; |
| 874 | #elif defined(SECOND) |
| 875 | template <class A> |
| 876 | struct S { |
| 877 | A a; |
| 878 | }; |
| 879 | #else |
| 880 | S<int> s; |
| 881 | #endif |
| 882 | |
| 883 | #if defined(FIRST) |
| 884 | template <class A> |
| 885 | struct T { |
| 886 | A a; |
| 887 | |
| 888 | private: |
| 889 | }; |
| 890 | #elif defined(SECOND) |
| 891 | template <class A> |
| 892 | struct T { |
| 893 | A a; |
| 894 | |
| 895 | public: |
| 896 | }; |
| 897 | #else |
| 898 | T<int> t; |
| 899 | // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 900 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 901 | #endif |
| 902 | } // namespace TemplateClassWithField |
| 903 | |
| 904 | namespace TemplateClassWithTemplateField { |
| 905 | #if defined(FIRST) |
| 906 | template <class A> |
| 907 | class WrapperS; |
| 908 | template <class A> |
| 909 | struct S { |
| 910 | WrapperS<A> a; |
| 911 | }; |
| 912 | #elif defined(SECOND) |
| 913 | template <class A> |
| 914 | class WrapperS; |
| 915 | template <class A> |
| 916 | struct S { |
| 917 | WrapperS<A> a; |
| 918 | }; |
| 919 | #else |
| 920 | template <class A> |
| 921 | class WrapperS{}; |
| 922 | S<int> s; |
| 923 | #endif |
| 924 | |
| 925 | #if defined(FIRST) |
| 926 | template <class A> |
| 927 | class WrapperT; |
| 928 | template <class A> |
| 929 | struct T { |
| 930 | WrapperT<A> a; |
| 931 | |
| 932 | public: |
| 933 | }; |
| 934 | #elif defined(SECOND) |
| 935 | template <class A> |
| 936 | class WrapperT; |
| 937 | template <class A> |
| 938 | struct T { |
| 939 | WrapperT<A> a; |
| 940 | |
| 941 | private: |
| 942 | }; |
| 943 | #else |
| 944 | template <class A> |
| 945 | class WrapperT{}; |
| 946 | T<int> t; |
| 947 | // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 948 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 949 | #endif |
| 950 | } // namespace TemplateClassWithTemplateField |
| 951 | |
| 952 | namespace EnumWithForwardDeclaration { |
| 953 | #if defined(FIRST) |
| 954 | enum E : int; |
| 955 | struct S { |
| 956 | void get(E) {} |
| 957 | }; |
| 958 | #elif defined(SECOND) |
| 959 | enum E : int { A, B }; |
| 960 | struct S { |
| 961 | void get(E) {} |
| 962 | }; |
| 963 | #else |
| 964 | S s; |
| 965 | #endif |
| 966 | |
| 967 | #if defined(FIRST) |
| 968 | struct T { |
| 969 | void get(E) {} |
| 970 | public: |
| 971 | }; |
| 972 | #elif defined(SECOND) |
| 973 | struct T { |
| 974 | void get(E) {} |
| 975 | private: |
| 976 | }; |
| 977 | #else |
| 978 | T t; |
| 979 | // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 980 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 981 | #endif |
| 982 | } // namespace EnumWithForwardDeclaration |
| 983 | |
| 984 | namespace StructWithForwardDeclaration { |
| 985 | #if defined(FIRST) |
| 986 | struct P {}; |
| 987 | struct S { |
| 988 | struct P *ptr; |
| 989 | }; |
| 990 | #elif defined(SECOND) |
| 991 | struct S { |
| 992 | struct P *ptr; |
| 993 | }; |
| 994 | #else |
| 995 | S s; |
| 996 | #endif |
| 997 | |
| 998 | #if defined(FIRST) |
| 999 | struct Q {}; |
| 1000 | struct T { |
| 1001 | struct Q *ptr; |
| 1002 | public: |
| 1003 | }; |
| 1004 | #elif defined(SECOND) |
| 1005 | struct T { |
| 1006 | struct Q *ptr; |
| 1007 | private: |
| 1008 | }; |
| 1009 | #else |
| 1010 | T t; |
| 1011 | // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1012 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1013 | #endif |
| 1014 | } // namespace StructWithForwardDeclaration |
| 1015 | |
| 1016 | namespace StructWithForwardDeclarationNoDefinition { |
| 1017 | #if defined(FIRST) |
| 1018 | struct P; |
| 1019 | struct S { |
| 1020 | struct P *ptr; |
| 1021 | }; |
| 1022 | #elif defined(SECOND) |
| 1023 | struct S { |
| 1024 | struct P *ptr; |
| 1025 | }; |
| 1026 | #else |
| 1027 | S s; |
| 1028 | #endif |
| 1029 | |
| 1030 | #if defined(FIRST) |
| 1031 | struct Q; |
| 1032 | struct T { |
| 1033 | struct Q *ptr; |
| 1034 | |
| 1035 | public: |
| 1036 | }; |
| 1037 | #elif defined(SECOND) |
| 1038 | struct T { |
| 1039 | struct Q *ptr; |
| 1040 | |
| 1041 | private: |
| 1042 | }; |
| 1043 | #else |
| 1044 | T t; |
| 1045 | // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1046 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1047 | #endif |
| 1048 | } // namespace StructWithForwardDeclarationNoDefinition |
| 1049 | |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1050 | namespace LateParsedDefaultArgument { |
| 1051 | #if defined(FIRST) |
| 1052 | template <typename T> |
| 1053 | struct S { |
| 1054 | struct R { |
| 1055 | void foo(T x = 0) {} |
| 1056 | }; |
| 1057 | }; |
| 1058 | #elif defined(SECOND) |
| 1059 | #else |
| 1060 | void run() { |
| 1061 | S<int>::R().foo(); |
| 1062 | } |
| 1063 | #endif |
| 1064 | } |
| 1065 | |
| 1066 | namespace LateParsedDefaultArgument { |
| 1067 | #if defined(FIRST) |
| 1068 | template <typename alpha> struct Bravo { |
| 1069 | void charlie(bool delta = false) {} |
| 1070 | }; |
| 1071 | typedef Bravo<char> echo; |
| 1072 | echo foxtrot; |
| 1073 | |
| 1074 | Bravo<char> golf; |
| 1075 | #elif defined(SECOND) |
| 1076 | #else |
| 1077 | #endif |
| 1078 | } |
| 1079 | |
Richard Trieu | 157ed94 | 2017-04-28 22:03:28 +0000 | [diff] [blame] | 1080 | namespace DifferentParameterNameInTemplate { |
| 1081 | #if defined(FIRST) || defined(SECOND) |
| 1082 | template <typename T> |
| 1083 | struct S { |
| 1084 | typedef T Type; |
| 1085 | |
| 1086 | static void Run(const Type *name_one); |
| 1087 | }; |
| 1088 | |
| 1089 | template <typename T> |
| 1090 | void S<T>::Run(const T *name_two) {} |
| 1091 | |
| 1092 | template <typename T> |
| 1093 | struct Foo { |
| 1094 | ~Foo() { Handler::Run(nullptr); } |
| 1095 | Foo() {} |
| 1096 | |
| 1097 | class Handler : public S<T> {}; |
| 1098 | |
| 1099 | void Get(typename Handler::Type *x = nullptr) {} |
| 1100 | void Add() { Handler::Run(nullptr); } |
| 1101 | }; |
| 1102 | #endif |
| 1103 | |
| 1104 | #if defined(FIRST) |
| 1105 | struct Beta; |
| 1106 | |
| 1107 | struct Alpha { |
| 1108 | Alpha(); |
| 1109 | void Go() { betas.Get(); } |
| 1110 | Foo<Beta> betas; |
| 1111 | }; |
| 1112 | |
| 1113 | #elif defined(SECOND) |
| 1114 | struct Beta {}; |
| 1115 | |
| 1116 | struct BetaHelper { |
| 1117 | void add_Beta() { betas.Add(); } |
| 1118 | Foo<Beta> betas; |
| 1119 | }; |
| 1120 | |
| 1121 | #else |
| 1122 | Alpha::Alpha() {} |
| 1123 | #endif |
| 1124 | } |
| 1125 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1126 | namespace ParameterTest { |
| 1127 | #if defined(FIRST) |
| 1128 | class X {}; |
| 1129 | template <typename G> |
| 1130 | class S { |
| 1131 | public: |
| 1132 | typedef G Type; |
| 1133 | static inline G *Foo(const G *a, int * = nullptr); |
| 1134 | }; |
| 1135 | |
| 1136 | template<typename G> |
| 1137 | G* S<G>::Foo(const G* aaaa, int*) {} |
| 1138 | #elif defined(SECOND) |
| 1139 | template <typename G> |
| 1140 | class S { |
| 1141 | public: |
| 1142 | typedef G Type; |
| 1143 | static inline G *Foo(const G *a, int * = nullptr); |
| 1144 | }; |
| 1145 | |
| 1146 | template<typename G> |
| 1147 | G* S<G>::Foo(const G* asdf, int*) {} |
| 1148 | #else |
| 1149 | S<X> s; |
| 1150 | #endif |
| 1151 | } |
| 1152 | |
Richard Trieu | b35ef2a | 2017-05-09 03:24:34 +0000 | [diff] [blame] | 1153 | namespace MultipleTypedefs { |
| 1154 | #if defined(FIRST) |
| 1155 | typedef int B1; |
| 1156 | typedef B1 A1; |
| 1157 | struct S1 { |
| 1158 | A1 x; |
| 1159 | }; |
| 1160 | #elif defined(SECOND) |
| 1161 | typedef int A1; |
| 1162 | struct S1 { |
| 1163 | A1 x; |
| 1164 | }; |
| 1165 | #else |
| 1166 | S1 s1; |
| 1167 | #endif |
| 1168 | |
| 1169 | #if defined(FIRST) |
| 1170 | struct T2 { int x; }; |
| 1171 | typedef T2 B2; |
| 1172 | typedef B2 A2; |
| 1173 | struct S2 { |
| 1174 | T2 x; |
| 1175 | }; |
| 1176 | #elif defined(SECOND) |
| 1177 | struct T2 { int x; }; |
| 1178 | typedef T2 A2; |
| 1179 | struct S2 { |
| 1180 | T2 x; |
| 1181 | }; |
| 1182 | #else |
| 1183 | S2 s2; |
| 1184 | #endif |
| 1185 | } |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1186 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1187 | // Keep macros contained to one file. |
| 1188 | #ifdef FIRST |
| 1189 | #undef FIRST |
| 1190 | #endif |
| 1191 | #ifdef SECOND |
| 1192 | #undef SECOND |
| 1193 | #endif |