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 1504 namespace TemplateParameters { 1505 #if defined(FIRST) 1506 template <class A> 1507 struct S1 {}; 1508 #elif defined(SECOND) 1509 template <class B> 1510 struct S1 {}; 1511 #else 1512 using TemplateParameters::S1; 1513 // [email protected]:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}} 1514 // [email protected]:* {{but in 'FirstModule' found template parameter 'A'}} 1515 #endif 1516 1517 #if defined(FIRST) 1518 template <class A = double> 1519 struct S2 {}; 1520 #elif defined(SECOND) 1521 template <class A = int> 1522 struct S2 {}; 1523 #else 1524 using TemplateParameters::S2; 1525 // [email protected]:* {{'TemplateParameters::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 1526 // [email protected]:* {{but in 'FirstModule' found template parameter with different default argument}} 1527 #endif 1528 1529 #if defined(FIRST) 1530 template <class A = int> 1531 struct S3 {}; 1532 #elif defined(SECOND) 1533 template <class A> 1534 struct S3 {}; 1535 #else 1536 using TemplateParameters::S3; 1537 // [email protected]:* {{'TemplateParameters::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with no default argument}} 1538 // [email protected]:* {{but in 'FirstModule' found template parameter with default argument}} 1539 #endif 1540 1541 #if defined(FIRST) 1542 template <int A> 1543 struct S4 {}; 1544 #elif defined(SECOND) 1545 template <int A = 2> 1546 struct S4 {}; 1547 #else 1548 using TemplateParameters::S4; 1549 // [email protected]:* {{'TemplateParameters::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 1550 // [email protected]:* {{but in 'FirstModule' found template parameter with no default argument}} 1551 #endif 1552 1553 #if defined(FIRST) 1554 template <int> class S5_first {}; 1555 template <template<int> class A = S5_first> 1556 struct S5 {}; 1557 #elif defined(SECOND) 1558 template <int> class S5_second {}; 1559 template <template<int> class A = S5_second> 1560 struct S5 {}; 1561 #else 1562 using TemplateParameters::S5; 1563 // [email protected]:* {{'TemplateParameters::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 1564 // [email protected]:* {{but in 'FirstModule' found template parameter with different default argument}} 1565 #endif 1566 1567 #if defined(FIRST) 1568 template <class A> 1569 struct S6 {}; 1570 #elif defined(SECOND) 1571 template <class> 1572 struct S6 {}; 1573 #else 1574 using TemplateParameters::S6; 1575 // [email protected]:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}} 1576 // [email protected]:* {{but in 'FirstModule' found template parameter 'A'}} 1577 #endif 1578 } // namespace TemplateParameters 1579 1580 // Interesting cases that should not cause errors. struct S should not error 1581 // while struct T should error at the access specifier mismatch at the end. 1582 namespace AllDecls { 1583 #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \ 1584 typedef int INT; \ 1585 struct NAME { \ 1586 public: \ 1587 private: \ 1588 protected: \ 1589 static_assert(1 == 1, "Message"); \ 1590 static_assert(2 == 2); \ 1591 \ 1592 int x; \ 1593 double y; \ 1594 \ 1595 INT z; \ 1596 \ 1597 unsigned a : 1; \ 1598 unsigned b : 2 * 2 + 5 / 2; \ 1599 \ 1600 mutable int c = sizeof(x + y); \ 1601 \ 1602 void method() {} \ 1603 static void static_method() {} \ 1604 virtual void virtual_method() {} \ 1605 virtual void pure_virtual_method() = 0; \ 1606 inline void inline_method() {} \ 1607 void volatile_method() volatile {} \ 1608 void const_method() const {} \ 1609 \ 1610 typedef int typedef_int; \ 1611 using using_int = int; \ 1612 \ 1613 void method_one_arg(int x) {} \ 1614 void method_one_arg_default_argument(int x = 5 + 5) {} \ 1615 void method_decayed_type(int x[5]) {} \ 1616 \ 1617 int constant_arr[5]; \ 1618 \ 1619 ACCESS: \ 1620 }; 1621 1622 #if defined(FIRST) 1623 CREATE_ALL_DECL_STRUCT(S, public) 1624 #elif defined(SECOND) 1625 CREATE_ALL_DECL_STRUCT(S, public) 1626 #else 1627 S *s; 1628 #endif 1629 1630 #if defined(FIRST) 1631 CREATE_ALL_DECL_STRUCT(T, private) 1632 #elif defined(SECOND) 1633 CREATE_ALL_DECL_STRUCT(T, public) 1634 #else 1635 T *t; 1636 // [email protected]:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1637 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1638 #endif 1639 } 1640 1641 namespace FriendFunction { 1642 #if defined(FIRST) 1643 void F(int = 0); 1644 struct S { friend void F(int); }; 1645 #elif defined(SECOND) 1646 void F(int); 1647 struct S { friend void F(int); }; 1648 #else 1649 S s; 1650 #endif 1651 1652 #if defined(FIRST) 1653 void G(int = 0); 1654 struct T { 1655 friend void G(int); 1656 1657 private: 1658 }; 1659 #elif defined(SECOND) 1660 void G(int); 1661 struct T { 1662 friend void G(int); 1663 1664 public: 1665 }; 1666 #else 1667 T t; 1668 // [email protected]:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1669 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1670 #endif 1671 } // namespace FriendFunction 1672 1673 namespace ImplicitDecl { 1674 #if defined(FIRST) 1675 struct S { }; 1676 void S_Constructors() { 1677 // Trigger creation of implicit contructors 1678 S foo; 1679 S bar = foo; 1680 S baz(bar); 1681 } 1682 #elif defined(SECOND) 1683 struct S { }; 1684 #else 1685 S s; 1686 #endif 1687 1688 #if defined(FIRST) 1689 struct T { 1690 private: 1691 }; 1692 void T_Constructors() { 1693 // Trigger creation of implicit contructors 1694 T foo; 1695 T bar = foo; 1696 T baz(bar); 1697 } 1698 #elif defined(SECOND) 1699 struct T { 1700 public: 1701 }; 1702 #else 1703 T t; 1704 // [email protected]:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} 1705 // [email protected]:* {{but in 'SecondModule' found public access specifier}} 1706 #endif 1707 1708 } // namespace ImplicitDelc 1709 1710 namespace TemplatedClass { 1711 #if defined(FIRST) 1712 template <class> 1713 struct S {}; 1714 #elif defined(SECOND) 1715 template <class> 1716 struct S {}; 1717 #else 1718 S<int> s; 1719 #endif 1720 1721 #if defined(FIRST) 1722 template <class> 1723 struct T { 1724 private: 1725 }; 1726 #elif defined(SECOND) 1727 template <class> 1728 struct T { 1729 public: 1730 }; 1731 #else 1732 T<int> t; 1733 // [email protected]:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1734 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1735 #endif 1736 } // namespace TemplatedClass 1737 1738 namespace TemplateClassWithField { 1739 #if defined(FIRST) 1740 template <class A> 1741 struct S { 1742 A a; 1743 }; 1744 #elif defined(SECOND) 1745 template <class A> 1746 struct S { 1747 A a; 1748 }; 1749 #else 1750 S<int> s; 1751 #endif 1752 1753 #if defined(FIRST) 1754 template <class A> 1755 struct T { 1756 A a; 1757 1758 private: 1759 }; 1760 #elif defined(SECOND) 1761 template <class A> 1762 struct T { 1763 A a; 1764 1765 public: 1766 }; 1767 #else 1768 T<int> t; 1769 // [email protected]:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 1770 // [email protected]:* {{but in 'FirstModule' found private access specifier}} 1771 #endif 1772 } // namespace TemplateClassWithField 1773 1774 namespace TemplateClassWithTemplateField { 1775 #if defined(FIRST) 1776 template <class A> 1777 class WrapperS; 1778 template <class A> 1779 struct S { 1780 WrapperS<A> a; 1781 }; 1782 #elif defined(SECOND) 1783 template <class A> 1784 class WrapperS; 1785 template <class A> 1786 struct S { 1787 WrapperS<A> a; 1788 }; 1789 #else 1790 template <class A> 1791 class WrapperS{}; 1792 S<int> s; 1793 #endif 1794 1795 #if defined(FIRST) 1796 template <class A> 1797 class WrapperT; 1798 template <class A> 1799 struct T { 1800 WrapperT<A> a; 1801 1802 public: 1803 }; 1804 #elif defined(SECOND) 1805 template <class A> 1806 class WrapperT; 1807 template <class A> 1808 struct T { 1809 WrapperT<A> a; 1810 1811 private: 1812 }; 1813 #else 1814 template <class A> 1815 class WrapperT{}; 1816 T<int> t; 1817 // [email protected]:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1818 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1819 #endif 1820 } // namespace TemplateClassWithTemplateField 1821 1822 namespace EnumWithForwardDeclaration { 1823 #if defined(FIRST) 1824 enum E : int; 1825 struct S { 1826 void get(E) {} 1827 }; 1828 #elif defined(SECOND) 1829 enum E : int { A, B }; 1830 struct S { 1831 void get(E) {} 1832 }; 1833 #else 1834 S s; 1835 #endif 1836 1837 #if defined(FIRST) 1838 struct T { 1839 void get(E) {} 1840 public: 1841 }; 1842 #elif defined(SECOND) 1843 struct T { 1844 void get(E) {} 1845 private: 1846 }; 1847 #else 1848 T t; 1849 // [email protected]:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1850 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1851 #endif 1852 } // namespace EnumWithForwardDeclaration 1853 1854 namespace StructWithForwardDeclaration { 1855 #if defined(FIRST) 1856 struct P {}; 1857 struct S { 1858 struct P *ptr; 1859 }; 1860 #elif defined(SECOND) 1861 struct S { 1862 struct P *ptr; 1863 }; 1864 #else 1865 S s; 1866 #endif 1867 1868 #if defined(FIRST) 1869 struct Q {}; 1870 struct T { 1871 struct Q *ptr; 1872 public: 1873 }; 1874 #elif defined(SECOND) 1875 struct T { 1876 struct Q *ptr; 1877 private: 1878 }; 1879 #else 1880 T t; 1881 // [email protected]:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1882 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1883 #endif 1884 } // namespace StructWithForwardDeclaration 1885 1886 namespace StructWithForwardDeclarationNoDefinition { 1887 #if defined(FIRST) 1888 struct P; 1889 struct S { 1890 struct P *ptr; 1891 }; 1892 #elif defined(SECOND) 1893 struct S { 1894 struct P *ptr; 1895 }; 1896 #else 1897 S s; 1898 #endif 1899 1900 #if defined(FIRST) 1901 struct Q; 1902 struct T { 1903 struct Q *ptr; 1904 1905 public: 1906 }; 1907 #elif defined(SECOND) 1908 struct T { 1909 struct Q *ptr; 1910 1911 private: 1912 }; 1913 #else 1914 T t; 1915 // [email protected]:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1916 // [email protected]:* {{but in 'FirstModule' found public access specifier}} 1917 #endif 1918 } // namespace StructWithForwardDeclarationNoDefinition 1919 1920 namespace LateParsedDefaultArgument { 1921 #if defined(FIRST) 1922 template <typename T> 1923 struct S { 1924 struct R { 1925 void foo(T x = 0) {} 1926 }; 1927 }; 1928 #elif defined(SECOND) 1929 #else 1930 void run() { 1931 S<int>::R().foo(); 1932 } 1933 #endif 1934 } 1935 1936 namespace LateParsedDefaultArgument { 1937 #if defined(FIRST) 1938 template <typename alpha> struct Bravo { 1939 void charlie(bool delta = false) {} 1940 }; 1941 typedef Bravo<char> echo; 1942 echo foxtrot; 1943 1944 Bravo<char> golf; 1945 #elif defined(SECOND) 1946 #else 1947 #endif 1948 } 1949 1950 namespace DifferentParameterNameInTemplate { 1951 #if defined(FIRST) || defined(SECOND) 1952 template <typename T> 1953 struct S { 1954 typedef T Type; 1955 1956 static void Run(const Type *name_one); 1957 }; 1958 1959 template <typename T> 1960 void S<T>::Run(const T *name_two) {} 1961 1962 template <typename T> 1963 struct Foo { 1964 ~Foo() { Handler::Run(nullptr); } 1965 Foo() {} 1966 1967 class Handler : public S<T> {}; 1968 1969 void Get(typename Handler::Type *x = nullptr) {} 1970 void Add() { Handler::Run(nullptr); } 1971 }; 1972 #endif 1973 1974 #if defined(FIRST) 1975 struct Beta; 1976 1977 struct Alpha { 1978 Alpha(); 1979 void Go() { betas.Get(); } 1980 Foo<Beta> betas; 1981 }; 1982 1983 #elif defined(SECOND) 1984 struct Beta {}; 1985 1986 struct BetaHelper { 1987 void add_Beta() { betas.Add(); } 1988 Foo<Beta> betas; 1989 }; 1990 1991 #else 1992 Alpha::Alpha() {} 1993 #endif 1994 } 1995 1996 namespace ParameterTest { 1997 #if defined(FIRST) 1998 class X {}; 1999 template <typename G> 2000 class S { 2001 public: 2002 typedef G Type; 2003 static inline G *Foo(const G *a, int * = nullptr); 2004 }; 2005 2006 template<typename G> 2007 G* S<G>::Foo(const G* aaaa, int*) {} 2008 #elif defined(SECOND) 2009 template <typename G> 2010 class S { 2011 public: 2012 typedef G Type; 2013 static inline G *Foo(const G *a, int * = nullptr); 2014 }; 2015 2016 template<typename G> 2017 G* S<G>::Foo(const G* asdf, int*) {} 2018 #else 2019 S<X> s; 2020 #endif 2021 } 2022 2023 namespace MultipleTypedefs { 2024 #if defined(FIRST) 2025 typedef int B1; 2026 typedef B1 A1; 2027 struct S1 { 2028 A1 x; 2029 }; 2030 #elif defined(SECOND) 2031 typedef int A1; 2032 struct S1 { 2033 A1 x; 2034 }; 2035 #else 2036 S1 s1; 2037 #endif 2038 2039 #if defined(FIRST) 2040 struct T2 { int x; }; 2041 typedef T2 B2; 2042 typedef B2 A2; 2043 struct S2 { 2044 T2 x; 2045 }; 2046 #elif defined(SECOND) 2047 struct T2 { int x; }; 2048 typedef T2 A2; 2049 struct S2 { 2050 T2 x; 2051 }; 2052 #else 2053 S2 s2; 2054 #endif 2055 2056 #if defined(FIRST) 2057 using A3 = const int; 2058 using B3 = volatile A3; 2059 struct S3 { 2060 B3 x = 1; 2061 }; 2062 #elif defined(SECOND) 2063 using A3 = volatile const int; 2064 using B3 = A3; 2065 struct S3 { 2066 B3 x = 1; 2067 }; 2068 #else 2069 S3 s3; 2070 #endif 2071 } 2072 2073 // Keep macros contained to one file. 2074 #ifdef FIRST 2075 #undef FIRST 2076 #endif 2077 #ifdef SECOND 2078 #undef SECOND 2079 #endif 2080