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 24 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z 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 // [email protected]:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 42 // [email protected]:* {{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 // [email protected]:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}} 56 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 57 #endif 58 } // namespace AccessSpecifiers 59 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 // [email protected]:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}} 72 // [email protected]:* {{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 // [email protected]:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}} 86 // [email protected]:* {{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 // [email protected]:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}} 100 // [email protected]:* {{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 // [email protected]:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 114 // [email protected]:* {{but in 'FirstModule' found static assert}} 115 #endif 116 } 117 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 // [email protected]:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} 133 // [email protected]:* {{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 // [email protected]:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} 149 // [email protected]:* {{but in 'FirstModule' found field 'x'}} 150 #endif 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 // [email protected]:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}} 163 // [email protected]:* {{declaration of 'x' does not match}} 164 #endif 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; 186 // [email protected]:* {{'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 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}} 188 189 S5 s5; 190 // [email protected]:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}} 191 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}} 192 #endif 193 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 // [email protected]:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}} 205 // [email protected]:* {{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 // [email protected]:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}} 219 // [email protected]:* {{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 // [email protected]:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}} 233 // [email protected]:* {{but in 'FirstModule' found bitfield 'x' with different width expression}} 234 #endif 235 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 // [email protected]:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}} 247 // [email protected]:* {{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 // [email protected]:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initalizer}} 261 // [email protected]:* {{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 // [email protected]:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}} 275 // [email protected]:* {{but in 'FirstModule' found field 'x' with a different initializer}} 276 #endif 277 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 // [email protected]:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}} 289 // [email protected]:* {{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 // [email protected]:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}} 303 // [email protected]:* {{declaration of 'x' does not match}} 304 #endif 305 } // namespace Field 306 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 // [email protected]:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 320 // [email protected]:* {{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 // [email protected]:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}} 336 // [email protected]:* {{but in 'FirstModule' found method 'A'}} 337 #endif 338 339 #if defined(FIRST) 340 struct S3 { 341 static void A() {} 342 void A(int) {} 343 }; 344 #elif defined(SECOND) 345 struct S3 { 346 void A(int) {} 347 static void A() {} 348 }; 349 #else 350 S3 s3; 351 // [email protected]:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}} 352 // [email protected]:* {{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 // [email protected]:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}} 368 // [email protected]:* {{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 // [email protected]:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}} 384 // [email protected]:* {{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 // [email protected]:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}} 398 // [email protected]:* {{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 // [email protected]:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}} 414 // [email protected]:* {{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 // [email protected]:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}} 430 // [email protected]:* {{but in 'FirstModule' found method 'A' is const}} 431 #endif 432 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 // [email protected]:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}} 446 // [email protected]:* {{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 // [email protected]:* {{'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 // [email protected]:* {{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 // [email protected]:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}} 476 // [email protected]:* {{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 // [email protected]:* {{'Method::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter without a default argument}} 490 // [email protected]:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}} 491 #endif 492 493 #if defined(FIRST) 494 struct S13 { 495 void A(int x = 1 + 0) {} 496 }; 497 #elif defined(SECOND) 498 struct S13 { 499 void A(int x = 1) {} 500 }; 501 #else 502 S13 s13; 503 // [email protected]:* {{'Method::S13' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter with a default argument}} 504 // [email protected]:* {{but in 'FirstModule' found method 'A' with 1st parameter with a different default argument}} 505 #endif 506 507 #if defined(FIRST) 508 struct S14 { 509 void A(int x[2]) {} 510 }; 511 #elif defined(SECOND) 512 struct S14 { 513 void A(int x[3]) {} 514 }; 515 #else 516 S14 s14; 517 // [email protected]:* {{'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]'}} 518 // [email protected]:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}} 519 #endif 520 521 #if defined(FIRST) 522 struct S15 { 523 int A() { return 0; } 524 }; 525 #elif defined(SECOND) 526 struct S15 { 527 long A() { return 0; } 528 }; 529 #else 530 S15 s15; 531 // [email protected]:* {{'Method::S15::A' from module 'FirstModule' is not present in definition of 'Method::S15' in module 'SecondModule'}} 532 // [email protected]:* {{declaration of 'A' does not match}} 533 #endif 534 } // namespace Method 535 536 namespace Constructor { 537 #if defined(FIRST) 538 struct S1 { 539 S1() {} 540 void foo() {} 541 }; 542 #elif defined(SECOND) 543 struct S1 { 544 void foo() {} 545 S1() {} 546 }; 547 #else 548 S1 s1; 549 // [email protected]:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}} 550 // [email protected]:* {{but in 'FirstModule' found constructor}} 551 #endif 552 553 #if defined(FIRST) 554 struct S2 { 555 S2(int) {} 556 S2(int, int) {} 557 }; 558 #elif defined(SECOND) 559 struct S2 { 560 S2(int, int) {} 561 S2(int) {} 562 }; 563 #else 564 S2* s2; 565 // [email protected]:* {{'Constructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor that has 2 parameters}} 566 // [email protected]:* {{but in 'FirstModule' found constructor that has 1 parameter}} 567 #endif 568 } // namespace Constructor 569 570 namespace Destructor { 571 #if defined(FIRST) 572 struct S1 { 573 ~S1() {} 574 S1() {} 575 }; 576 #elif defined(SECOND) 577 struct S1 { 578 S1() {} 579 ~S1() {} 580 }; 581 #else 582 S1 s1; 583 // [email protected]:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}} 584 // [email protected]:* {{but in 'FirstModule' found destructor}} 585 #endif 586 587 #if defined(FIRST) 588 struct S2 { 589 virtual ~S2() {} 590 void foo() {} 591 }; 592 #elif defined(SECOND) 593 struct S2 { 594 ~S2() {} 595 virtual void foo() {} 596 }; 597 #else 598 S2 s2; 599 // [email protected]:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}} 600 // [email protected]:* {{but in 'FirstModule' found destructor is virtual}} 601 #endif 602 603 } // namespace Destructor 604 605 // Naive parsing of AST can lead to cycles in processing. Ensure 606 // self-references don't trigger an endless cycles of AST node processing. 607 namespace SelfReference { 608 #if defined(FIRST) 609 template <template <int> class T> class Wrapper {}; 610 611 template <int N> class S { 612 S(Wrapper<::SelfReference::S> &Ref) {} 613 }; 614 615 struct Xx { 616 struct Yy { 617 }; 618 }; 619 620 Xx::Xx::Xx::Yy yy; 621 622 namespace NNS { 623 template <typename> struct Foo; 624 template <template <class> class T = NNS::Foo> 625 struct NestedNamespaceSpecifier {}; 626 } 627 #endif 628 } // namespace SelfReference 629 630 namespace TypeDef { 631 #if defined(FIRST) 632 struct S1 { 633 typedef int a; 634 }; 635 #elif defined(SECOND) 636 struct S1 { 637 typedef double a; 638 }; 639 #else 640 S1 s1; 641 // [email protected]:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}} 642 // [email protected]:* {{declaration of 'a' does not match}} 643 #endif 644 645 #if defined(FIRST) 646 struct S2 { 647 typedef int a; 648 }; 649 #elif defined(SECOND) 650 struct S2 { 651 typedef int b; 652 }; 653 #else 654 S2 s2; 655 // [email protected]:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}} 656 // [email protected]:* {{definition has no member 'a'}} 657 #endif 658 659 #if defined(FIRST) 660 typedef int T; 661 struct S3 { 662 typedef T a; 663 }; 664 #elif defined(SECOND) 665 typedef double T; 666 struct S3 { 667 typedef T a; 668 }; 669 #else 670 S3 s3; 671 // [email protected]:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}} 672 // [email protected]:* {{declaration of 'a' does not match}} 673 #endif 674 675 #if defined(FIRST) 676 struct S4 { 677 typedef int a; 678 typedef int b; 679 }; 680 #elif defined(SECOND) 681 struct S4 { 682 typedef int b; 683 typedef int a; 684 }; 685 #else 686 S4 s4; 687 // [email protected]:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}} 688 // [email protected]:* {{but in 'FirstModule' found typedef name 'a'}} 689 #endif 690 691 #if defined(FIRST) 692 struct S5 { 693 typedef int a; 694 typedef int b; 695 int x; 696 }; 697 #elif defined(SECOND) 698 struct S5 { 699 int x; 700 typedef int b; 701 typedef int a; 702 }; 703 #else 704 S5 s5; 705 // [email protected]:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} 706 // [email protected]:* {{but in 'FirstModule' found typedef}} 707 #endif 708 709 #if defined(FIRST) 710 typedef float F; 711 struct S6 { 712 typedef int a; 713 typedef F b; 714 }; 715 #elif defined(SECOND) 716 struct S6 { 717 typedef int a; 718 typedef float b; 719 }; 720 #else 721 S6 s6; 722 // [email protected]:* {{'TypeDef::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef 'b' with underlying type 'float'}} 723 // [email protected]:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}} 724 #endif 725 } // namespace TypeDef 726 727 namespace Using { 728 #if defined(FIRST) 729 struct S1 { 730 using a = int; 731 }; 732 #elif defined(SECOND) 733 struct S1 { 734 using a = double; 735 }; 736 #else 737 S1 s1; 738 // [email protected]:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}} 739 // [email protected]:* {{declaration of 'a' does not match}} 740 #endif 741 742 #if defined(FIRST) 743 struct S2 { 744 using a = int; 745 }; 746 #elif defined(SECOND) 747 struct S2 { 748 using b = int; 749 }; 750 #else 751 S2 s2; 752 // [email protected]:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}} 753 // [email protected]:* {{definition has no member 'a'}} 754 #endif 755 756 #if defined(FIRST) 757 typedef int T; 758 struct S3 { 759 using a = T; 760 }; 761 #elif defined(SECOND) 762 typedef double T; 763 struct S3 { 764 using a = T; 765 }; 766 #else 767 S3 s3; 768 // [email protected]:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}} 769 // [email protected]:* {{declaration of 'a' does not match}} 770 #endif 771 772 #if defined(FIRST) 773 struct S4 { 774 using a = int; 775 using b = int; 776 }; 777 #elif defined(SECOND) 778 struct S4 { 779 using b = int; 780 using a = int; 781 }; 782 #else 783 S4 s4; 784 // [email protected]:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}} 785 // [email protected]:* {{but in 'FirstModule' found type alias name 'a'}} 786 #endif 787 788 #if defined(FIRST) 789 struct S5 { 790 using a = int; 791 using b = int; 792 int x; 793 }; 794 #elif defined(SECOND) 795 struct S5 { 796 int x; 797 using b = int; 798 using a = int; 799 }; 800 #else 801 S5 s5; 802 // [email protected]:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} 803 // [email protected]:* {{but in 'FirstModule' found type alias}} 804 #endif 805 806 #if defined(FIRST) 807 typedef float F; 808 struct S6 { 809 using a = int; 810 using b = F; 811 }; 812 #elif defined(SECOND) 813 struct S6 { 814 using a = int; 815 using b = float; 816 }; 817 #else 818 S6 s6; 819 // [email protected]:* {{'Using::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'b' with underlying type 'float'}} 820 // [email protected]:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}} 821 #endif 822 } // namespace Using 823 824 namespace RecordType { 825 #if defined(FIRST) 826 struct B1 {}; 827 struct S1 { 828 B1 x; 829 }; 830 #elif defined(SECOND) 831 struct A1 {}; 832 struct S1 { 833 A1 x; 834 }; 835 #else 836 S1 s1; 837 // [email protected]:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}} 838 // [email protected]:* {{declaration of 'x' does not match}} 839 #endif 840 } 841 842 namespace DependentType { 843 #if defined(FIRST) 844 template <class T> 845 class S1 { 846 typename T::typeA x; 847 }; 848 #elif defined(SECOND) 849 template <class T> 850 class S1 { 851 typename T::typeB x; 852 }; 853 #else 854 template<class T> 855 using U1 = S1<T>; 856 // [email protected]:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}} 857 // [email protected]:* {{declaration of 'x' does not match}} 858 #endif 859 } 860 861 namespace ElaboratedType { 862 #if defined(FIRST) 863 namespace N1 { using type = double; } 864 struct S1 { 865 N1::type x; 866 }; 867 #elif defined(SECOND) 868 namespace N1 { using type = int; } 869 struct S1 { 870 N1::type x; 871 }; 872 #else 873 S1 s1; 874 // [email protected]:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}} 875 // [email protected]:* {{declaration of 'x' does not match}} 876 #endif 877 } 878 879 namespace Enum { 880 #if defined(FIRST) 881 enum A1 {}; 882 struct S1 { 883 A1 x; 884 }; 885 #elif defined(SECOND) 886 enum A2 {}; 887 struct S1 { 888 A2 x; 889 }; 890 #else 891 S1 s1; 892 // [email protected]:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}} 893 // [email protected]:* {{declaration of 'x' does not match}} 894 #endif 895 } 896 897 namespace NestedNamespaceSpecifier { 898 #if defined(FIRST) 899 namespace LevelA1 { 900 using Type = int; 901 } 902 903 struct S1 { 904 LevelA1::Type x; 905 }; 906 # elif defined(SECOND) 907 namespace LevelB1 { 908 namespace LevelC1 { 909 using Type = int; 910 } 911 } 912 913 struct S1 { 914 LevelB1::LevelC1::Type x; 915 }; 916 #else 917 S1 s1; 918 // [email protected]:* {{'NestedNamespaceSpecifier::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB1::LevelC1::Type' (aka 'int')}} 919 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}} 920 #endif 921 922 #if defined(FIRST) 923 namespace LevelA2 { using Type = int; } 924 struct S2 { 925 LevelA2::Type x; 926 }; 927 # elif defined(SECOND) 928 struct S2 { 929 int x; 930 }; 931 #else 932 S2 s2; 933 // [email protected]:* {{'NestedNamespaceSpecifier::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}} 934 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}} 935 #endif 936 937 namespace LevelA3 { using Type = int; } 938 namespace LevelB3 { using Type = int; } 939 #if defined(FIRST) 940 struct S3 { 941 LevelA3::Type x; 942 }; 943 # elif defined(SECOND) 944 struct S3 { 945 LevelB3::Type x; 946 }; 947 #else 948 S3 s3; 949 // [email protected]:* {{'NestedNamespaceSpecifier::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB3::Type' (aka 'int')}} 950 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}} 951 #endif 952 953 #if defined(FIRST) 954 struct TA4 { using Type = int; }; 955 struct S4 { 956 TA4::Type x; 957 }; 958 # elif defined(SECOND) 959 struct TB4 { using Type = int; }; 960 struct S4 { 961 TB4::Type x; 962 }; 963 #else 964 S4 s4; 965 // [email protected]:* {{'NestedNamespaceSpecifier::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'TB4::Type' (aka 'int')}} 966 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}} 967 #endif 968 969 #if defined(FIRST) 970 struct T5 { using Type = int; }; 971 struct S5 { 972 T5::Type x; 973 }; 974 # elif defined(SECOND) 975 namespace T5 { using Type = int; }; 976 struct S5 { 977 T5::Type x; 978 }; 979 #else 980 S5 s5; 981 // [email protected]:* {{'NestedNamespaceSpecifier::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'T5::Type' (aka 'int')}} 982 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}} 983 #endif 984 985 #if defined(FIRST) 986 namespace N6 {using I = int;} 987 struct S6 { 988 NestedNamespaceSpecifier::N6::I x; 989 }; 990 # elif defined(SECOND) 991 using I = int; 992 struct S6 { 993 ::NestedNamespaceSpecifier::I x; 994 }; 995 #else 996 S6 s6; 997 // [email protected]:* {{'NestedNamespaceSpecifier::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '::NestedNamespaceSpecifier::I' (aka 'int')}} 998 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}} 999 #endif 1000 1001 #if defined(FIRST) 1002 template <class T, class U> 1003 class S7 { 1004 typename T::type *x = {}; 1005 int z = x->T::foo(); 1006 }; 1007 #elif defined(SECOND) 1008 template <class T, class U> 1009 class S7 { 1010 typename T::type *x = {}; 1011 int z = x->U::foo(); 1012 }; 1013 #else 1014 template <class T, class U> 1015 using U7 = S7<T, U>; 1016 // [email protected]:* {{'NestedNamespaceSpecifier::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'z' with an initializer}} 1017 // [email protected]:* {{but in 'FirstModule' found field 'z' with a different initializer}} 1018 #endif 1019 1020 #if defined(FIRST) 1021 template <class T> 1022 class S8 { 1023 int x = T::template X<int>::value; 1024 }; 1025 #elif defined(SECOND) 1026 template <class T> 1027 class S8 { 1028 int x = T::template Y<int>::value; 1029 }; 1030 #else 1031 template <class T> 1032 using U8 = S8<T>; 1033 // [email protected]:* {{'NestedNamespaceSpecifier::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}} 1034 // [email protected]:* {{but in 'FirstModule' found field 'x' with a different initializer}} 1035 #endif 1036 1037 #if defined(FIRST) 1038 namespace N9 { using I = int; } 1039 namespace O9 = N9; 1040 struct S9 { 1041 O9::I x; 1042 }; 1043 #elif defined(SECOND) 1044 namespace N9 { using I = int; } 1045 namespace P9 = N9; 1046 struct S9 { 1047 P9::I x; 1048 }; 1049 #else 1050 S9 s9; 1051 // [email protected]:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}} 1052 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}} 1053 #endif 1054 1055 namespace N10 { 1056 #if defined(FIRST) 1057 inline namespace A { struct X {}; } 1058 struct S10 { 1059 A::X x; 1060 }; 1061 #elif defined(SECOND) 1062 inline namespace B { struct X {}; } 1063 struct S10 { 1064 B::X x; 1065 }; 1066 #else 1067 S10 s10; 1068 // [email protected]:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}} 1069 // [email protected]:* {{declaration of 'x' does not match}} 1070 #endif 1071 } 1072 } 1073 1074 namespace TemplateSpecializationType { 1075 #if defined(FIRST) 1076 template <class T1> struct U1 {}; 1077 struct S1 { 1078 U1<int> u; 1079 }; 1080 #elif defined(SECOND) 1081 template <class T1, class T2> struct U1 {}; 1082 struct S1 { 1083 U1<int, int> u; 1084 }; 1085 #else 1086 S1 s1; 1087 // [email protected]:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}} 1088 // [email protected]:* {{declaration of 'u' does not match}} 1089 #endif 1090 1091 #if defined(FIRST) 1092 template <class T1> struct U2 {}; 1093 struct S2 { 1094 U2<int> u; 1095 }; 1096 #elif defined(SECOND) 1097 template <class T1> struct V1 {}; 1098 struct S2 { 1099 V1<int> u; 1100 }; 1101 #else 1102 S2 s2; 1103 // [email protected]:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}} 1104 // [email protected]:* {{declaration of 'u' does not match}} 1105 #endif 1106 } 1107 1108 namespace TemplateArgument { 1109 #if defined(FIRST) 1110 template <class> struct U1{}; 1111 struct S1 { 1112 U1<int> x; 1113 }; 1114 #elif defined(SECOND) 1115 template <int> struct U1{}; 1116 struct S1 { 1117 U1<1> x; 1118 }; 1119 #else 1120 S1 s1; 1121 // [email protected]:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}} 1122 // [email protected]:* {{declaration of 'x' does not match}} 1123 #endif 1124 1125 #if defined(FIRST) 1126 template <int> struct U2{}; 1127 struct S2 { 1128 using T = U2<2>; 1129 }; 1130 #elif defined(SECOND) 1131 template <int> struct U2{}; 1132 struct S2 { 1133 using T = U2<(2)>; 1134 }; 1135 #else 1136 S2 s2; 1137 // [email protected]:* {{'TemplateArgument::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U2<(2)>'}} 1138 // [email protected]:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}} 1139 #endif 1140 1141 #if defined(FIRST) 1142 template <int> struct U3{}; 1143 struct S3 { 1144 using T = U3<2>; 1145 }; 1146 #elif defined(SECOND) 1147 template <int> struct U3{}; 1148 struct S3 { 1149 using T = U3<1 + 1>; 1150 }; 1151 #else 1152 S3 s3; 1153 // [email protected]:* {{'TemplateArgument::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U3<1 + 1>'}} 1154 // [email protected]:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}} 1155 #endif 1156 1157 #if defined(FIRST) 1158 template<class> struct T4a {}; 1159 template <template <class> class T> struct U4 {}; 1160 struct S4 { 1161 U4<T4a> x; 1162 }; 1163 #elif defined(SECOND) 1164 template<class> struct T4b {}; 1165 template <template <class> class T> struct U4 {}; 1166 struct S4 { 1167 U4<T4b> x; 1168 }; 1169 #else 1170 S4 s4; 1171 // [email protected]:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}} 1172 // [email protected]:* {{declaration of 'x' does not match}} 1173 #endif 1174 1175 #if defined(FIRST) 1176 template <class T> struct U5 {}; 1177 struct S5 { 1178 U5<int> x; 1179 }; 1180 #elif defined(SECOND) 1181 template <class T> struct U5 {}; 1182 struct S5 { 1183 U5<short> x; 1184 }; 1185 #else 1186 S5 s5; 1187 // [email protected]:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}} 1188 // [email protected]:* {{declaration of 'x' does not match}} 1189 #endif 1190 1191 #if defined(FIRST) 1192 template <class T> struct U6 {}; 1193 struct S6 { 1194 U6<int> x; 1195 U6<short> y; 1196 }; 1197 #elif defined(SECOND) 1198 template <class T> struct U6 {}; 1199 struct S6 { 1200 U6<short> y; 1201 U6<int> x; 1202 }; 1203 #else 1204 S6 s6; 1205 // [email protected]:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} 1206 // [email protected]:* {{but in 'FirstModule' found field 'x'}} 1207 #endif 1208 } 1209 1210 namespace TemplateTypeParmType { 1211 #if defined(FIRST) 1212 template <class T1, class T2> 1213 struct S1 { 1214 T1 x; 1215 }; 1216 #elif defined(SECOND) 1217 template <class T1, class T2> 1218 struct S1 { 1219 T2 x; 1220 }; 1221 #else 1222 using TemplateTypeParmType::S1; 1223 // [email protected]:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}} 1224 // [email protected]:* {{declaration of 'x' does not match}} 1225 #endif 1226 1227 #if defined(FIRST) 1228 template <int ...Ts> 1229 struct U2 {}; 1230 template <int T, int U> 1231 class S2 { 1232 typedef U2<U, T> type; 1233 type x; 1234 }; 1235 #elif defined(SECOND) 1236 template <int ...Ts> 1237 struct U2 {}; 1238 template <int T, int U> 1239 class S2 { 1240 typedef U2<T, U> type; 1241 type x; 1242 }; 1243 #else 1244 using TemplateTypeParmType::S2; 1245 // [email protected]:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}} 1246 // [email protected]:* {{declaration of 'x' does not match}} 1247 // [email protected]:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}} 1248 // [email protected]:* {{declaration of 'type' does not match}} 1249 #endif 1250 } 1251 1252 namespace VarDecl { 1253 #if defined(FIRST) 1254 struct S1 { 1255 static int x; 1256 static int y; 1257 }; 1258 #elif defined(SECOND) 1259 struct S1 { 1260 static int y; 1261 static int x; 1262 }; 1263 #else 1264 S1 s1; 1265 // [email protected]:* {{'VarDecl::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member with name 'y'}} 1266 // [email protected]:* {{but in 'FirstModule' found data member with name 'x'}} 1267 #endif 1268 1269 #if defined(FIRST) 1270 struct S2 { 1271 static int x; 1272 }; 1273 #elif defined(SECOND) 1274 using I = int; 1275 struct S2 { 1276 static I x; 1277 }; 1278 #else 1279 S2 s2; 1280 // [email protected]:* {{'VarDecl::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with type 'VarDecl::I' (aka 'int')}} 1281 // [email protected]:* {{but in 'FirstModule' found data member 'x' with different type 'int'}} 1282 #endif 1283 1284 #if defined(FIRST) 1285 struct S3 { 1286 static const int x = 1; 1287 }; 1288 #elif defined(SECOND) 1289 struct S3 { 1290 static const int x; 1291 }; 1292 #else 1293 S3 s3; 1294 // [email protected]:* {{'VarDecl::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with an initializer}} 1295 // [email protected]:* {{but in 'FirstModule' found data member 'x' without an initializer}} 1296 #endif 1297 1298 #if defined(FIRST) 1299 struct S4 { 1300 static const int x = 1; 1301 }; 1302 #elif defined(SECOND) 1303 struct S4 { 1304 static const int x = 2; 1305 }; 1306 #else 1307 S4 s4; 1308 // [email protected]:* {{'VarDecl::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with an initializer}} 1309 // [email protected]:* {{but in 'FirstModule' found data member 'x' with a different initializer}} 1310 #endif 1311 1312 #if defined(FIRST) 1313 struct S5 { 1314 static const int x = 1; 1315 }; 1316 #elif defined(SECOND) 1317 struct S5 { 1318 static constexpr int x = 1; 1319 }; 1320 #else 1321 S5 s5; 1322 // [email protected]:* {{'VarDecl::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' is not constexpr}} 1323 // [email protected]:* {{but in 'FirstModule' found data member 'x' is constexpr}} 1324 #endif 1325 1326 #if defined(FIRST) 1327 struct S6 { 1328 static const int x = 1; 1329 }; 1330 #elif defined(SECOND) 1331 struct S6 { 1332 static const int y = 1; 1333 }; 1334 #else 1335 S6 s6; 1336 // [email protected]:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}} 1337 // [email protected]:* {{definition has no member 'x'}} 1338 #endif 1339 1340 #if defined(FIRST) 1341 struct S7 { 1342 static const int x = 1; 1343 }; 1344 #elif defined(SECOND) 1345 struct S7 { 1346 static const unsigned x = 1; 1347 }; 1348 #else 1349 S7 s7; 1350 // [email protected]:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}} 1351 // [email protected]:* {{declaration of 'x' does not match}} 1352 #endif 1353 1354 #if defined(FIRST) 1355 struct S8 { 1356 public: 1357 static const int x = 1; 1358 }; 1359 #elif defined(SECOND) 1360 struct S8 { 1361 static const int x = 1; 1362 public: 1363 }; 1364 #else 1365 S8 s8; 1366 // [email protected]:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}} 1367 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1368 #endif 1369 1370 #if defined(FIRST) 1371 struct S9 { 1372 static const int x = 1; 1373 }; 1374 #elif defined(SECOND) 1375 struct S9 { 1376 static int x; 1377 }; 1378 #else 1379 S9 s9; 1380 // [email protected]:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}} 1381 // [email protected]:* {{declaration of 'x' does not match}} 1382 #endif 1383 1384 #if defined(FIRST) 1385 template <typename T> 1386 struct S { 1387 struct R { 1388 void foo(T x = 0) {} 1389 }; 1390 }; 1391 #elif defined(SECOND) 1392 template <typename T> 1393 struct S { 1394 struct R { 1395 void foo(T x = 1) {} 1396 }; 1397 }; 1398 #else 1399 void run() { 1400 S<int>::R().foo(); 1401 } 1402 // [email protected]:* {{'VarDecl::S::R' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo' with 1st parameter with a default argument}} 1403 // [email protected]:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}} 1404 #endif 1405 1406 #if defined(FIRST) 1407 template <typename alpha> struct Bravo { 1408 void charlie(bool delta = false) {} 1409 }; 1410 typedef Bravo<char> echo; 1411 echo foxtrot; 1412 #elif defined(SECOND) 1413 template <typename alpha> struct Bravo { 1414 void charlie(bool delta = (false)) {} 1415 }; 1416 typedef Bravo<char> echo; 1417 echo foxtrot; 1418 #else 1419 Bravo<char> golf; 1420 // [email protected]:* {{'VarDecl::Bravo' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'charlie' with 1st parameter with a default argument}} 1421 // [email protected]:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}} 1422 #endif 1423 } 1424 1425 namespace Friend { 1426 #if defined(FIRST) 1427 struct T1 {}; 1428 struct S1 { 1429 friend class T1; 1430 }; 1431 #elif defined(SECOND) 1432 struct T1 {}; 1433 struct S1 { 1434 friend T1; 1435 }; 1436 #else 1437 S1 s1; 1438 // [email protected]:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T1'}} 1439 // [email protected]:* {{but in 'FirstModule' found friend 'class T1'}} 1440 #endif 1441 1442 #if defined(FIRST) 1443 struct T2 {}; 1444 struct S2 { 1445 friend class T2; 1446 }; 1447 #elif defined(SECOND) 1448 struct T2 {}; 1449 struct S2 { 1450 friend struct T2; 1451 }; 1452 #else 1453 S2 s2; 1454 // [email protected]:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}} 1455 // [email protected]:* {{but in 'FirstModule' found friend 'class T2'}} 1456 #endif 1457 1458 #if defined(FIRST) 1459 struct T3 {}; 1460 struct S3 { 1461 friend const T3; 1462 }; 1463 #elif defined(SECOND) 1464 struct T3 {}; 1465 struct S3 { 1466 friend T3; 1467 }; 1468 #else 1469 S3 s3; 1470 // [email protected]:* {{'Friend::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T3'}} 1471 // [email protected]:* {{but in 'FirstModule' found friend 'const Friend::T3'}} 1472 #endif 1473 1474 #if defined(FIRST) 1475 struct T4 {}; 1476 struct S4 { 1477 friend T4; 1478 }; 1479 #elif defined(SECOND) 1480 struct S4 { 1481 friend void T4(); 1482 }; 1483 #else 1484 S4 s4; 1485 // [email protected]:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}} 1486 // [email protected]:* {{but in 'FirstModule' found friend class}} 1487 #endif 1488 1489 #if defined(FIRST) 1490 struct S5 { 1491 friend void T5a(); 1492 }; 1493 #elif defined(SECOND) 1494 struct S5 { 1495 friend void T5b(); 1496 }; 1497 #else 1498 S5 s5; 1499 // [email protected]:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}} 1500 // [email protected]:* {{but in 'FirstModule' found friend function 'T5a'}} 1501 #endif 1502 } 1503 // Interesting cases that should not cause errors. struct S should not error 1504 // while struct T should error at the access specifier mismatch at the end. 1505 namespace AllDecls { 1506 #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \ 1507 typedef int INT; \ 1508 struct NAME { \ 1509 public: \ 1510 private: \ 1511 protected: \ 1512 static_assert(1 == 1, "Message"); \ 1513 static_assert(2 == 2); \ 1514 \ 1515 int x; \ 1516 double y; \ 1517 \ 1518 INT z; \ 1519 \ 1520 unsigned a : 1; \ 1521 unsigned b : 2 * 2 + 5 / 2; \ 1522 \ 1523 mutable int c = sizeof(x + y); \ 1524 \ 1525 void method() {} \ 1526 static void static_method() {} \ 1527 virtual void virtual_method() {} \ 1528 virtual void pure_virtual_method() = 0; \ 1529 inline void inline_method() {} \ 1530 void volatile_method() volatile {} \ 1531 void const_method() const {} \ 1532 \ 1533 typedef int typedef_int; \ 1534 using using_int = int; \ 1535 \ 1536 void method_one_arg(int x) {} \ 1537 void method_one_arg_default_argument(int x = 5 + 5) {} \ 1538 void method_decayed_type(int x[5]) {} \ 1539 \ 1540 int constant_arr[5]; \ 1541 \ 1542 ACCESS: \ 1543 }; 1544 1545 #if defined(FIRST) 1546 CREATE_ALL_DECL_STRUCT(S, public) 1547 #elif defined(SECOND) 1548 CREATE_ALL_DECL_STRUCT(S, public) 1549 #else 1550 S *s; 1551 #endif 1552 1553 #if defined(FIRST) 1554 CREATE_ALL_DECL_STRUCT(T, private) 1555 #elif defined(SECOND) 1556 CREATE_ALL_DECL_STRUCT(T, public) 1557 #else 1558 T *t; 1559 // [email protected]:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1560 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1561 #endif 1562 } 1563 1564 namespace FriendFunction { 1565 #if defined(FIRST) 1566 void F(int = 0); 1567 struct S { friend void F(int); }; 1568 #elif defined(SECOND) 1569 void F(int); 1570 struct S { friend void F(int); }; 1571 #else 1572 S s; 1573 #endif 1574 1575 #if defined(FIRST) 1576 void G(int = 0); 1577 struct T { 1578 friend void G(int); 1579 1580 private: 1581 }; 1582 #elif defined(SECOND) 1583 void G(int); 1584 struct T { 1585 friend void G(int); 1586 1587 public: 1588 }; 1589 #else 1590 T t; 1591 // [email protected]:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1592 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1593 #endif 1594 } // namespace FriendFunction 1595 1596 namespace ImplicitDecl { 1597 #if defined(FIRST) 1598 struct S { }; 1599 void S_Constructors() { 1600 // Trigger creation of implicit contructors 1601 S foo; 1602 S bar = foo; 1603 S baz(bar); 1604 } 1605 #elif defined(SECOND) 1606 struct S { }; 1607 #else 1608 S s; 1609 #endif 1610 1611 #if defined(FIRST) 1612 struct T { 1613 private: 1614 }; 1615 void T_Constructors() { 1616 // Trigger creation of implicit contructors 1617 T foo; 1618 T bar = foo; 1619 T baz(bar); 1620 } 1621 #elif defined(SECOND) 1622 struct T { 1623 public: 1624 }; 1625 #else 1626 T t; 1627 // [email protected]:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} 1628 // [email protected]:* {{but in 'SecondModule' found public access specifier}} 1629 #endif 1630 1631 } // namespace ImplicitDelc 1632 1633 namespace TemplatedClass { 1634 #if defined(FIRST) 1635 template <class> 1636 struct S {}; 1637 #elif defined(SECOND) 1638 template <class> 1639 struct S {}; 1640 #else 1641 S<int> s; 1642 #endif 1643 1644 #if defined(FIRST) 1645 template <class> 1646 struct T { 1647 private: 1648 }; 1649 #elif defined(SECOND) 1650 template <class> 1651 struct T { 1652 public: 1653 }; 1654 #else 1655 T<int> t; 1656 // [email protected]:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1657 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1658 #endif 1659 } // namespace TemplatedClass 1660 1661 namespace TemplateClassWithField { 1662 #if defined(FIRST) 1663 template <class A> 1664 struct S { 1665 A a; 1666 }; 1667 #elif defined(SECOND) 1668 template <class A> 1669 struct S { 1670 A a; 1671 }; 1672 #else 1673 S<int> s; 1674 #endif 1675 1676 #if defined(FIRST) 1677 template <class A> 1678 struct T { 1679 A a; 1680 1681 private: 1682 }; 1683 #elif defined(SECOND) 1684 template <class A> 1685 struct T { 1686 A a; 1687 1688 public: 1689 }; 1690 #else 1691 T<int> t; 1692 // [email protected]:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1693 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1694 #endif 1695 } // namespace TemplateClassWithField 1696 1697 namespace TemplateClassWithTemplateField { 1698 #if defined(FIRST) 1699 template <class A> 1700 class WrapperS; 1701 template <class A> 1702 struct S { 1703 WrapperS<A> a; 1704 }; 1705 #elif defined(SECOND) 1706 template <class A> 1707 class WrapperS; 1708 template <class A> 1709 struct S { 1710 WrapperS<A> a; 1711 }; 1712 #else 1713 template <class A> 1714 class WrapperS{}; 1715 S<int> s; 1716 #endif 1717 1718 #if defined(FIRST) 1719 template <class A> 1720 class WrapperT; 1721 template <class A> 1722 struct T { 1723 WrapperT<A> a; 1724 1725 public: 1726 }; 1727 #elif defined(SECOND) 1728 template <class A> 1729 class WrapperT; 1730 template <class A> 1731 struct T { 1732 WrapperT<A> a; 1733 1734 private: 1735 }; 1736 #else 1737 template <class A> 1738 class WrapperT{}; 1739 T<int> t; 1740 // [email protected]:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1741 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1742 #endif 1743 } // namespace TemplateClassWithTemplateField 1744 1745 namespace EnumWithForwardDeclaration { 1746 #if defined(FIRST) 1747 enum E : int; 1748 struct S { 1749 void get(E) {} 1750 }; 1751 #elif defined(SECOND) 1752 enum E : int { A, B }; 1753 struct S { 1754 void get(E) {} 1755 }; 1756 #else 1757 S s; 1758 #endif 1759 1760 #if defined(FIRST) 1761 struct T { 1762 void get(E) {} 1763 public: 1764 }; 1765 #elif defined(SECOND) 1766 struct T { 1767 void get(E) {} 1768 private: 1769 }; 1770 #else 1771 T t; 1772 // [email protected]:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1773 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1774 #endif 1775 } // namespace EnumWithForwardDeclaration 1776 1777 namespace StructWithForwardDeclaration { 1778 #if defined(FIRST) 1779 struct P {}; 1780 struct S { 1781 struct P *ptr; 1782 }; 1783 #elif defined(SECOND) 1784 struct S { 1785 struct P *ptr; 1786 }; 1787 #else 1788 S s; 1789 #endif 1790 1791 #if defined(FIRST) 1792 struct Q {}; 1793 struct T { 1794 struct Q *ptr; 1795 public: 1796 }; 1797 #elif defined(SECOND) 1798 struct T { 1799 struct Q *ptr; 1800 private: 1801 }; 1802 #else 1803 T t; 1804 // [email protected]:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1805 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1806 #endif 1807 } // namespace StructWithForwardDeclaration 1808 1809 namespace StructWithForwardDeclarationNoDefinition { 1810 #if defined(FIRST) 1811 struct P; 1812 struct S { 1813 struct P *ptr; 1814 }; 1815 #elif defined(SECOND) 1816 struct S { 1817 struct P *ptr; 1818 }; 1819 #else 1820 S s; 1821 #endif 1822 1823 #if defined(FIRST) 1824 struct Q; 1825 struct T { 1826 struct Q *ptr; 1827 1828 public: 1829 }; 1830 #elif defined(SECOND) 1831 struct T { 1832 struct Q *ptr; 1833 1834 private: 1835 }; 1836 #else 1837 T t; 1838 // [email protected]:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1839 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1840 #endif 1841 } // namespace StructWithForwardDeclarationNoDefinition 1842 1843 namespace LateParsedDefaultArgument { 1844 #if defined(FIRST) 1845 template <typename T> 1846 struct S { 1847 struct R { 1848 void foo(T x = 0) {} 1849 }; 1850 }; 1851 #elif defined(SECOND) 1852 #else 1853 void run() { 1854 S<int>::R().foo(); 1855 } 1856 #endif 1857 } 1858 1859 namespace LateParsedDefaultArgument { 1860 #if defined(FIRST) 1861 template <typename alpha> struct Bravo { 1862 void charlie(bool delta = false) {} 1863 }; 1864 typedef Bravo<char> echo; 1865 echo foxtrot; 1866 1867 Bravo<char> golf; 1868 #elif defined(SECOND) 1869 #else 1870 #endif 1871 } 1872 1873 namespace DifferentParameterNameInTemplate { 1874 #if defined(FIRST) || defined(SECOND) 1875 template <typename T> 1876 struct S { 1877 typedef T Type; 1878 1879 static void Run(const Type *name_one); 1880 }; 1881 1882 template <typename T> 1883 void S<T>::Run(const T *name_two) {} 1884 1885 template <typename T> 1886 struct Foo { 1887 ~Foo() { Handler::Run(nullptr); } 1888 Foo() {} 1889 1890 class Handler : public S<T> {}; 1891 1892 void Get(typename Handler::Type *x = nullptr) {} 1893 void Add() { Handler::Run(nullptr); } 1894 }; 1895 #endif 1896 1897 #if defined(FIRST) 1898 struct Beta; 1899 1900 struct Alpha { 1901 Alpha(); 1902 void Go() { betas.Get(); } 1903 Foo<Beta> betas; 1904 }; 1905 1906 #elif defined(SECOND) 1907 struct Beta {}; 1908 1909 struct BetaHelper { 1910 void add_Beta() { betas.Add(); } 1911 Foo<Beta> betas; 1912 }; 1913 1914 #else 1915 Alpha::Alpha() {} 1916 #endif 1917 } 1918 1919 namespace ParameterTest { 1920 #if defined(FIRST) 1921 class X {}; 1922 template <typename G> 1923 class S { 1924 public: 1925 typedef G Type; 1926 static inline G *Foo(const G *a, int * = nullptr); 1927 }; 1928 1929 template<typename G> 1930 G* S<G>::Foo(const G* aaaa, int*) {} 1931 #elif defined(SECOND) 1932 template <typename G> 1933 class S { 1934 public: 1935 typedef G Type; 1936 static inline G *Foo(const G *a, int * = nullptr); 1937 }; 1938 1939 template<typename G> 1940 G* S<G>::Foo(const G* asdf, int*) {} 1941 #else 1942 S<X> s; 1943 #endif 1944 } 1945 1946 namespace MultipleTypedefs { 1947 #if defined(FIRST) 1948 typedef int B1; 1949 typedef B1 A1; 1950 struct S1 { 1951 A1 x; 1952 }; 1953 #elif defined(SECOND) 1954 typedef int A1; 1955 struct S1 { 1956 A1 x; 1957 }; 1958 #else 1959 S1 s1; 1960 #endif 1961 1962 #if defined(FIRST) 1963 struct T2 { int x; }; 1964 typedef T2 B2; 1965 typedef B2 A2; 1966 struct S2 { 1967 T2 x; 1968 }; 1969 #elif defined(SECOND) 1970 struct T2 { int x; }; 1971 typedef T2 A2; 1972 struct S2 { 1973 T2 x; 1974 }; 1975 #else 1976 S2 s2; 1977 #endif 1978 1979 #if defined(FIRST) 1980 using A3 = const int; 1981 using B3 = volatile A3; 1982 struct S3 { 1983 B3 x = 1; 1984 }; 1985 #elif defined(SECOND) 1986 using A3 = volatile const int; 1987 using B3 = A3; 1988 struct S3 { 1989 B3 x = 1; 1990 }; 1991 #else 1992 S3 s3; 1993 #endif 1994 } 1995 1996 // Keep macros contained to one file. 1997 #ifdef FIRST 1998 #undef FIRST 1999 #endif 2000 #ifdef SECOND 2001 #undef SECOND 2002 #endif 2003