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