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 // Test that each header can compile 16 // RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++20 %t/Inputs/first.h 17 // RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++20 %t/Inputs/second.h 18 19 // Build module map file 20 // RUN: echo "module FirstModule {" >> %t/Inputs/module.modulemap 21 // RUN: echo " header \"first.h\"" >> %t/Inputs/module.modulemap 22 // RUN: echo "}" >> %t/Inputs/module.modulemap 23 // RUN: echo "module SecondModule {" >> %t/Inputs/module.modulemap 24 // RUN: echo " header \"second.h\"" >> %t/Inputs/module.modulemap 25 // RUN: echo "}" >> %t/Inputs/module.modulemap 26 27 // Run test 28 // RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -std=c++20 \ 29 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \ 30 // RUN: -I%t/Inputs -verify %s 31 32 #if !defined(FIRST) && !defined(SECOND) 33 #include "first.h" 34 #include "second.h" 35 #endif 36 37 // Used for testing 38 #if defined(FIRST) 39 #define ACCESS public: 40 #elif defined(SECOND) 41 #define ACCESS private: 42 #endif 43 44 namespace AccessSpecifiers { 45 #if defined(FIRST) 46 struct S1 { 47 }; 48 #elif defined(SECOND) 49 struct S1 { 50 private: 51 }; 52 #else 53 S1 s1; 54 // expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 55 // expected-note@first.h:* {{but in 'FirstModule' found end of class}} 56 #endif 57 58 #if defined(FIRST) 59 struct S2 { 60 public: 61 }; 62 #elif defined(SECOND) 63 struct S2 { 64 protected: 65 }; 66 #else 67 S2 s2; 68 // expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}} 69 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 70 #endif 71 72 #define DECLS \ 73 public: \ 74 private: \ 75 protected: 76 77 #if defined(FIRST) || defined(SECOND) 78 struct Valid1 { 79 DECLS 80 }; 81 #else 82 Valid1 v1; 83 #endif 84 85 #if defined(FIRST) || defined(SECOND) 86 struct Invalid1 { 87 DECLS 88 ACCESS 89 }; 90 #else 91 Invalid1 i1; 92 // expected-error@second.h:* {{'AccessSpecifiers::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 93 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 94 #endif 95 96 #undef DECLS 97 } // namespace AccessSpecifiers 98 99 namespace StaticAssert { 100 #if defined(FIRST) 101 struct S1 { 102 static_assert(1 == 1, "First"); 103 }; 104 #elif defined(SECOND) 105 struct S1 { 106 static_assert(1 == 1, "Second"); 107 }; 108 #else 109 S1 s1; 110 // expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}} 111 // expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}} 112 #endif 113 114 #if defined(FIRST) 115 struct S2 { 116 static_assert(2 == 2, "Message"); 117 }; 118 #elif defined(SECOND) 119 struct S2 { 120 static_assert(2 == 2); 121 }; 122 #else 123 S2 s2; 124 // expected-error@second.h:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}} 125 // expected-note@first.h:* {{but in 'FirstModule' found static assert with message}} 126 #endif 127 128 #if defined(FIRST) 129 struct S3 { 130 static_assert(3 == 3, "Message"); 131 }; 132 #elif defined(SECOND) 133 struct S3 { 134 static_assert(3 != 4, "Message"); 135 }; 136 #else 137 S3 s3; 138 // expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}} 139 // expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}} 140 #endif 141 142 #if defined(FIRST) 143 struct S4 { 144 static_assert(4 == 4, "Message"); 145 }; 146 #elif defined(SECOND) 147 struct S4 { 148 public: 149 }; 150 #else 151 S4 s4; 152 // expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 153 // expected-note@first.h:* {{but in 'FirstModule' found static assert}} 154 #endif 155 156 #define DECLS \ 157 static_assert(4 == 4, "Message"); \ 158 static_assert(5 == 5); 159 160 #if defined(FIRST) || defined(SECOND) 161 struct Valid1 { 162 DECLS 163 }; 164 #else 165 Valid1 v1; 166 #endif 167 168 #if defined(FIRST) || defined(SECOND) 169 struct Invalid1 { 170 DECLS 171 ACCESS 172 }; 173 #else 174 Invalid1 i1; 175 // expected-error@second.h:* {{'StaticAssert::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 176 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 177 #endif 178 #undef DECLS 179 } // namespace StaticAssert 180 181 namespace Field { 182 #if defined(FIRST) 183 struct S1 { 184 int x; 185 private: 186 int y; 187 }; 188 #elif defined(SECOND) 189 struct S1 { 190 int x; 191 int y; 192 }; 193 #else 194 S1 s1; 195 // expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} 196 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} 197 #endif 198 199 #if defined(FIRST) 200 struct S2 { 201 int x; 202 int y; 203 }; 204 #elif defined(SECOND) 205 struct S2 { 206 int y; 207 int x; 208 }; 209 #else 210 S2 s2; 211 // expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} 212 // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}} 213 #endif 214 215 #if defined(FIRST) 216 struct S3 { 217 double x; 218 }; 219 #elif defined(SECOND) 220 struct S3 { 221 int x; 222 }; 223 #else 224 S3 s3; 225 // expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}} 226 // expected-note@second.h:* {{declaration of 'x' does not match}} 227 #endif 228 229 #if defined(FIRST) 230 typedef int A; 231 struct S4 { 232 A x; 233 }; 234 235 struct S5 { 236 A x; 237 }; 238 #elif defined(SECOND) 239 typedef int B; 240 struct S4 { 241 B x; 242 }; 243 244 struct S5 { 245 int x; 246 }; 247 #else 248 S4 s4; 249 // expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'B' (aka 'int')}} 250 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}} 251 252 S5 s5; 253 // expected-error@second.h:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}} 254 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}} 255 #endif 256 257 #if defined(FIRST) 258 struct S6 { 259 unsigned x; 260 }; 261 #elif defined(SECOND) 262 struct S6 { 263 unsigned x : 1; 264 }; 265 #else 266 S6 s6; 267 // expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bit-field 'x'}} 268 // expected-note@first.h:* {{but in 'FirstModule' found non-bit-field 'x'}} 269 #endif 270 271 #if defined(FIRST) 272 struct S7 { 273 unsigned x : 2; 274 }; 275 #elif defined(SECOND) 276 struct S7 { 277 unsigned x : 1; 278 }; 279 #else 280 S7 s7; 281 // expected-error@second.h:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bit-field 'x' with one width expression}} 282 // expected-note@first.h:* {{but in 'FirstModule' found bit-field 'x' with different width expression}} 283 #endif 284 285 #if defined(FIRST) 286 struct S8 { 287 unsigned x : 2; 288 }; 289 #elif defined(SECOND) 290 struct S8 { 291 unsigned x : 1 + 1; 292 }; 293 #else 294 S8 s8; 295 // expected-error@second.h:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bit-field 'x' with one width expression}} 296 // expected-note@first.h:* {{but in 'FirstModule' found bit-field 'x' with different width expression}} 297 #endif 298 299 #if defined(FIRST) 300 struct S9 { 301 mutable int x; 302 }; 303 #elif defined(SECOND) 304 struct S9 { 305 int x; 306 }; 307 #else 308 S9 s9; 309 // expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}} 310 // expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}} 311 #endif 312 313 #if defined(FIRST) 314 struct S9b { 315 mutable int x : 2; 316 }; 317 #elif defined(SECOND) 318 struct S9b { 319 int x : 2; 320 }; 321 #else 322 S9b s9b; 323 // expected-error@second.h:* {{'Field::S9b' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}} 324 // expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}} 325 #endif 326 327 #if defined(FIRST) 328 struct S10 { 329 unsigned x = 5; 330 }; 331 #elif defined(SECOND) 332 struct S10 { 333 unsigned x; 334 }; 335 #else 336 S10 s10; 337 // expected-error@second.h:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initializer}} 338 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}} 339 #endif 340 341 #if defined(FIRST) 342 struct S11 { 343 unsigned x = 5; 344 }; 345 #elif defined(SECOND) 346 struct S11 { 347 unsigned x = 7; 348 }; 349 #else 350 S11 s11; 351 // expected-error@second.h:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}} 352 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}} 353 #endif 354 355 #if defined(FIRST) 356 struct S12 { 357 unsigned x[5]; 358 }; 359 #elif defined(SECOND) 360 struct S12 { 361 unsigned x[7]; 362 }; 363 #else 364 S12 s12; 365 // expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}} 366 // expected-note@second.h:* {{declaration of 'x' does not match}} 367 #endif 368 369 #if defined(FIRST) 370 struct S13 { 371 unsigned x[7]; 372 }; 373 #elif defined(SECOND) 374 struct S13 { 375 double x[7]; 376 }; 377 #else 378 S13 s13; 379 // expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}} 380 // expected-note@second.h:* {{declaration of 'x' does not match}} 381 #endif 382 383 #define DECLS \ 384 int a; \ 385 int b : 3; \ 386 unsigned c : 1 + 2; \ 387 s d; \ 388 double e = 1.0; \ 389 long f[5]; \ 390 mutable int g; \ 391 mutable int h : 5; 392 393 #if defined(FIRST) || defined(SECOND) 394 typedef short s; 395 #endif 396 397 #if defined(FIRST) || defined(SECOND) 398 struct Valid1 { 399 DECLS 400 }; 401 #else 402 Valid1 v1; 403 #endif 404 405 #if defined(FIRST) || defined(SECOND) 406 struct Invalid1 { 407 DECLS 408 ACCESS 409 }; 410 #else 411 Invalid1 i1; 412 // expected-error@second.h:* {{'Field::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 413 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 414 #endif 415 #undef DECLS 416 } // namespace Field 417 418 namespace Method { 419 #if defined(FIRST) 420 struct S1 { 421 void A() {} 422 }; 423 #elif defined(SECOND) 424 struct S1 { 425 private: 426 void A() {} 427 }; 428 #else 429 S1 s1; 430 // expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 431 // expected-note@first.h:* {{but in 'FirstModule' found method}} 432 #endif 433 434 #if defined(FIRST) 435 struct S2 { 436 void A() {} 437 void B() {} 438 }; 439 #elif defined(SECOND) 440 struct S2 { 441 void B() {} 442 void A() {} 443 }; 444 #else 445 S2 s2; 446 // expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}} 447 // expected-note@first.h:* {{but in 'FirstModule' found method 'A'}} 448 #endif 449 450 #if defined(FIRST) 451 struct S3 { 452 static void A() {} 453 void A(int) {} 454 }; 455 #elif defined(SECOND) 456 struct S3 { 457 void A(int) {} 458 static void A() {} 459 }; 460 #else 461 S3 s3; 462 // expected-error@second.h:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}} 463 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}} 464 #endif 465 466 #if defined(FIRST) 467 struct S4 { 468 virtual void A() {} 469 void B() {} 470 }; 471 #elif defined(SECOND) 472 struct S4 { 473 void A() {} 474 virtual void B() {} 475 }; 476 #else 477 S4 s4; 478 // expected-error@second.h:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}} 479 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}} 480 #endif 481 482 #if defined(FIRST) 483 struct S5 { 484 virtual void A() = 0; 485 virtual void B() {}; 486 }; 487 #elif defined(SECOND) 488 struct S5 { 489 virtual void A() {} 490 virtual void B() = 0; 491 }; 492 #else 493 S5 *s5; 494 // expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}} 495 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}} 496 #endif 497 498 #if defined(FIRST) 499 struct S6 { 500 inline void A() {} 501 }; 502 #elif defined(SECOND) 503 struct S6 { 504 void A() {} 505 }; 506 #else 507 S6 s6; 508 // expected-error@second.h:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}} 509 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}} 510 #endif 511 512 #if defined(FIRST) 513 struct S7 { 514 void A() volatile {} 515 void A() {} 516 }; 517 #elif defined(SECOND) 518 struct S7 { 519 void A() {} 520 void A() volatile {} 521 }; 522 #else 523 S7 s7; 524 // expected-error@second.h:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}} 525 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}} 526 #endif 527 528 #if defined(FIRST) 529 struct S8 { 530 void A() const {} 531 void A() {} 532 }; 533 #elif defined(SECOND) 534 struct S8 { 535 void A() {} 536 void A() const {} 537 }; 538 #else 539 S8 s8; 540 // expected-error@second.h:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}} 541 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}} 542 #endif 543 544 #if defined(FIRST) 545 struct S9 { 546 void A(int x) {} 547 void A(int x, int y) {} 548 }; 549 #elif defined(SECOND) 550 struct S9 { 551 void A(int x, int y) {} 552 void A(int x) {} 553 }; 554 #else 555 S9 s9; 556 // expected-error@second.h:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}} 557 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}} 558 #endif 559 560 #if defined(FIRST) 561 struct S10 { 562 void A(int x) {} 563 void A(float x) {} 564 }; 565 #elif defined(SECOND) 566 struct S10 { 567 void A(float x) {} 568 void A(int x) {} 569 }; 570 #else 571 S10 s10; 572 // expected-error@second.h:* {{'Method::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'float'}} 573 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}} 574 #endif 575 576 #if defined(FIRST) 577 struct S11 { 578 void A(int x); 579 }; 580 #elif defined(SECOND) 581 struct S11 { 582 void A(int y); 583 }; 584 #else 585 S11 s11; 586 // expected-error@second.h:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}} 587 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}} 588 #endif 589 590 #if defined(FIRST) 591 struct S12 { 592 void A(int x); 593 }; 594 #elif defined(SECOND) 595 struct S12 { 596 void A(int x = 1); 597 }; 598 #else 599 S12 s12; 600 // expected-error@second.h:* {{'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}} 601 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}} 602 #endif 603 604 #if defined(FIRST) 605 struct S13 { 606 void A(int x = 1 + 0); 607 }; 608 #elif defined(SECOND) 609 struct S13 { 610 void A(int x = 1); 611 }; 612 #else 613 S13 s13; 614 // expected-error@second.h:* {{'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}} 615 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a different default argument}} 616 #endif 617 618 #if defined(FIRST) 619 struct S14 { 620 void A(int x[2]); 621 }; 622 #elif defined(SECOND) 623 struct S14 { 624 void A(int x[3]); 625 }; 626 #else 627 S14 s14; 628 // expected-error@second.h:* {{'Method::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int[3]'}} 629 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int[2]'}} 630 #endif 631 632 #if defined(FIRST) 633 struct S15 { 634 int A() { return 0; } 635 }; 636 #elif defined(SECOND) 637 struct S15 { 638 long A() { return 0; } 639 }; 640 #else 641 S15 s15; 642 // expected-error@first.h:* {{'Method::S15::A' from module 'FirstModule' is not present in definition of 'Method::S15' in module 'SecondModule'}} 643 // expected-note@second.h:* {{declaration of 'A' does not match}} 644 #endif 645 646 #define DECLS \ 647 void A(); \ 648 static void B(); \ 649 virtual void C(); \ 650 virtual void D() = 0; \ 651 inline void E(); \ 652 void F() const; \ 653 void G() volatile; \ 654 void H(int x); \ 655 void I(int x = 5 + 5); \ 656 void J(int); \ 657 void K(int x[2]); \ 658 int L(); 659 660 #if defined(FIRST) || defined(SECOND) 661 struct Valid1 { 662 DECLS 663 }; 664 #else 665 Valid1* v1; 666 #endif 667 668 #if defined(FIRST) || defined(SECOND) 669 struct Invalid1 { 670 DECLS 671 ACCESS 672 }; 673 #else 674 Invalid1* i1; 675 // expected-error@second.h:* {{'Method::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 676 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 677 #endif 678 #undef DECLS 679 } // namespace Method 680 681 namespace MethodBody { 682 #if defined(FIRST) 683 struct S1 { 684 int A() { return 0; } 685 }; 686 #elif defined(SECOND) 687 struct S1 { 688 int A() { return 0; } 689 }; 690 #else 691 S1 s1; 692 #endif 693 694 #if defined(FIRST) 695 struct S2 { 696 int BothBodies() { return 0; } 697 }; 698 #elif defined(SECOND) 699 struct S2 { 700 int BothBodies() { return 1; } 701 }; 702 #else 703 S2 s2; 704 // expected-error@first.h:* {{'MethodBody::S2' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'BothBodies' with body}} 705 // expected-note@second.h:* {{but in 'SecondModule' found method 'BothBodies' with different body}} 706 #endif 707 708 #if defined(FIRST) 709 struct S3 { 710 int FirstBody() { return 0; } 711 }; 712 #elif defined(SECOND) 713 struct S3 { 714 int FirstBody(); 715 }; 716 #else 717 S3 s3; 718 // expected-error@first.h:* {{'MethodBody::S3' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstBody' with body}} 719 // expected-note@second.h:* {{but in 'SecondModule' found method 'FirstBody' with no body}} 720 #endif 721 722 #if defined(FIRST) 723 struct S4 { 724 int SecondBody(); 725 }; 726 #elif defined(SECOND) 727 struct S4 { 728 int SecondBody() { return 0; } 729 }; 730 #else 731 S4 s4; 732 // expected-error@first.h:* {{'MethodBody::S4' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'SecondBody' with no body}} 733 // expected-note@second.h:* {{but in 'SecondModule' found method 'SecondBody' with body}} 734 #endif 735 736 #if defined(FIRST) 737 struct S5 { 738 int FirstBodySecondOutOfLine() { return 0; } 739 }; 740 #elif defined(SECOND) 741 struct S5 { 742 int FirstBodySecondOutOfLine(); 743 }; 744 int S5::FirstBodySecondOutOfLine() { return 0; } 745 #else 746 S5 s5; 747 // expected-error@second.h:* {{'MethodBody::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'FirstBodySecondOutOfLine' with no body}} 748 // expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}} 749 #endif 750 751 #if defined(FIRST) 752 struct S6 { 753 int FirstOutOfLineSecondBody(); 754 }; 755 int S6::FirstOutOfLineSecondBody() { return 0; } 756 #elif defined(SECOND) 757 struct S6 { 758 int FirstOutOfLineSecondBody() { return 0; } 759 }; 760 #else 761 S6 s6; 762 // expected-error@first.h:* {{'MethodBody::S6' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstOutOfLineSecondBody' with no body}} 763 // expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}} 764 #endif 765 766 #if defined(FIRST) 767 struct S7 { 768 int BothOutOfLine(); 769 }; 770 int S7::BothOutOfLine() { return 1; } 771 #elif defined(SECOND) 772 struct S7 { 773 int BothOutOfLine(); 774 }; 775 int S7::BothOutOfLine() { return 0; } 776 #else 777 S7 s7; 778 // expected-error@second.h:* {{'MethodBody::S7::BothOutOfLine' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 779 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 780 #endif 781 782 #if defined(FIRST) 783 struct S8 { 784 int FirstBodySecondOutOfLine() { return 0; } 785 }; 786 #elif defined(SECOND) 787 struct S8 { 788 int FirstBodySecondOutOfLine(); 789 }; 790 int S8::FirstBodySecondOutOfLine() { return 1; } 791 #else 792 S8 s8; 793 // expected-error@second.h:* {{'MethodBody::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'FirstBodySecondOutOfLine' with no body}} 794 // expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}} 795 #endif 796 797 #if defined(FIRST) 798 struct S9 { 799 int FirstOutOfLineSecondBody(); 800 }; 801 int S9::FirstOutOfLineSecondBody() { return 1; } 802 #elif defined(SECOND) 803 struct S9 { 804 int FirstOutOfLineSecondBody() { return 0; } 805 }; 806 #else 807 S9 s9; 808 // expected-error@first.h:* {{'MethodBody::S9' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstOutOfLineSecondBody' with no body}} 809 // expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}} 810 #endif 811 812 #if defined(FIRST) 813 struct S10 { 814 S10(int); 815 S10() = delete; 816 }; 817 #elif defined(SECOND) 818 struct S10 { 819 S10(int); 820 S10(); 821 }; 822 #else 823 S10 s10(10); 824 // expected-error@first.h:* {{'MethodBody::S10' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is deleted}} 825 // expected-note@second.h:* {{but in 'SecondModule' found constructor is not deleted}} 826 #endif 827 828 #if defined(FIRST) 829 struct S11 { 830 S11() = default; 831 }; 832 #elif defined(SECOND) 833 struct S11 { 834 S11(); 835 }; 836 #else 837 S11 s11; 838 // expected-error@first.h:* {{'MethodBody::S11' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is defaulted}} 839 // expected-note@second.h:* {{but in 'SecondModule' found constructor is not defaulted}} 840 #endif 841 842 #define DECLS(CLASSNAME) \ 843 CLASSNAME() = default; \ 844 ~CLASSNAME() = delete; \ 845 void A(); \ 846 void B() { return; }; \ 847 void C(); \ 848 void D(); 849 850 #define OUTOFLINEDEFS(CLASSNAME) \ 851 void CLASSNAME::C() {} \ 852 void CLASSNAME::D() { return; } 853 854 #if defined(FIRST) || defined(SECOND) 855 struct Valid1 { 856 DECLS(Valid1) 857 }; 858 OUTOFLINEDEFS(Valid1) 859 #else 860 Valid1* v1; 861 #endif 862 863 #if defined(FIRST) || defined(SECOND) 864 struct Invalid1 { 865 DECLS(Invalid1) 866 ACCESS 867 }; 868 OUTOFLINEDEFS(Invalid1) 869 #else 870 Invalid1* i1; 871 // expected-error@first.h:* {{'MethodBody::Invalid1' has different definitions in different modules; first difference is definition in module 'FirstModule' found public access specifier}} 872 // expected-note@second.h:* {{but in 'SecondModule' found private access specifier}} 873 #endif 874 #undef DECLS 875 } // namespace MethodBody 876 877 namespace Constructor { 878 #if defined(FIRST) 879 struct S1 { 880 S1() {} 881 void foo() {} 882 }; 883 #elif defined(SECOND) 884 struct S1 { 885 void foo() {} 886 S1() {} 887 }; 888 #else 889 S1 s1; 890 // expected-error@second.h:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}} 891 // expected-note@first.h:* {{but in 'FirstModule' found constructor}} 892 #endif 893 894 #if defined(FIRST) 895 struct S2 { 896 S2(int) {} 897 S2(int, int) {} 898 }; 899 #elif defined(SECOND) 900 struct S2 { 901 S2(int, int) {} 902 S2(int) {} 903 }; 904 #else 905 S2* s2; 906 // expected-error@second.h:* {{'Constructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor that has 2 parameters}} 907 // expected-note@first.h:* {{but in 'FirstModule' found constructor that has 1 parameter}} 908 #endif 909 910 #define DECLS(CLASS) \ 911 CLASS(int); \ 912 CLASS(double); \ 913 CLASS(int, int); 914 915 #if defined(FIRST) || defined(SECOND) 916 struct Valid1 { 917 DECLS(Valid1) 918 }; 919 #else 920 Valid1* v1; 921 #endif 922 923 #if defined(FIRST) || defined(SECOND) 924 struct Invalid1 { 925 DECLS(Invalid1) 926 ACCESS 927 }; 928 #else 929 Invalid1* i1; 930 // expected-error@second.h:* {{'Constructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 931 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 932 #endif 933 #undef DECLS 934 } // namespace Constructor 935 936 namespace Destructor { 937 #if defined(FIRST) 938 struct S1 { 939 ~S1() {} 940 S1() {} 941 }; 942 #elif defined(SECOND) 943 struct S1 { 944 S1() {} 945 ~S1() {} 946 }; 947 #else 948 S1 s1; 949 // expected-error@second.h:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}} 950 // expected-note@first.h:* {{but in 'FirstModule' found destructor}} 951 #endif 952 953 #if defined(FIRST) 954 struct S2 { 955 virtual ~S2() {} 956 void foo() {} 957 }; 958 #elif defined(SECOND) 959 struct S2 { 960 ~S2() {} 961 virtual void foo() {} 962 }; 963 #else 964 S2 s2; 965 // expected-error@second.h:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}} 966 // expected-note@first.h:* {{but in 'FirstModule' found destructor is virtual}} 967 #endif 968 969 #if defined(FIRST) || defined(SECOND) 970 struct Valid1 { 971 ~Valid1(); 972 }; 973 #else 974 Valid1 v1; 975 #endif 976 977 #if defined(FIRST) || defined(SECOND) 978 struct Invalid1 { 979 ~Invalid1(); 980 ACCESS 981 }; 982 #else 983 Invalid1 i1; 984 // expected-error@second.h:* {{'Destructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 985 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 986 #endif 987 988 #if defined(FIRST) || defined(SECOND) 989 struct Valid2 { 990 virtual ~Valid2(); 991 }; 992 #else 993 Valid2 v2; 994 #endif 995 996 #if defined(FIRST) || defined(SECOND) 997 struct Invalid2 { 998 virtual ~Invalid2(); 999 ACCESS 1000 }; 1001 #else 1002 Invalid2 i2; 1003 // expected-error@second.h:* {{'Destructor::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1004 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1005 #endif 1006 } // namespace Destructor 1007 1008 namespace TypeDef { 1009 #if defined(FIRST) 1010 struct S1 { 1011 typedef int a; 1012 }; 1013 #elif defined(SECOND) 1014 struct S1 { 1015 typedef double a; 1016 }; 1017 #else 1018 S1 s1; 1019 // expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}} 1020 // expected-note@second.h:* {{declaration of 'a' does not match}} 1021 #endif 1022 1023 #if defined(FIRST) 1024 struct S2 { 1025 typedef int a; 1026 }; 1027 #elif defined(SECOND) 1028 struct S2 { 1029 typedef int b; 1030 }; 1031 #else 1032 S2 s2; 1033 // expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}} 1034 // expected-note@second.h:* {{definition has no member 'a'}} 1035 #endif 1036 1037 #if defined(FIRST) 1038 typedef int T; 1039 struct S3 { 1040 typedef T a; 1041 }; 1042 #elif defined(SECOND) 1043 typedef double T; 1044 struct S3 { 1045 typedef T a; 1046 }; 1047 #else 1048 S3 s3; 1049 // FIXME: We should reject the merge of `S3` due to the inconsistent definition of `T`. 1050 #endif 1051 1052 #if defined(FIRST) 1053 struct S4 { 1054 typedef int a; 1055 typedef int b; 1056 }; 1057 #elif defined(SECOND) 1058 struct S4 { 1059 typedef int b; 1060 typedef int a; 1061 }; 1062 #else 1063 S4 s4; 1064 // expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}} 1065 // expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}} 1066 #endif 1067 1068 #if defined(FIRST) 1069 struct S5 { 1070 typedef int a; 1071 typedef int b; 1072 int x; 1073 }; 1074 #elif defined(SECOND) 1075 struct S5 { 1076 int x; 1077 typedef int b; 1078 typedef int a; 1079 }; 1080 #else 1081 S5 s5; 1082 // expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} 1083 // expected-note@first.h:* {{but in 'FirstModule' found typedef}} 1084 #endif 1085 1086 #if defined(FIRST) 1087 typedef float F; 1088 struct S6 { 1089 typedef int a; 1090 typedef F b; 1091 }; 1092 #elif defined(SECOND) 1093 struct S6 { 1094 typedef int a; 1095 typedef float b; 1096 }; 1097 #else 1098 S6 s6; 1099 // expected-error@second.h:* {{'TypeDef::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef 'b' with underlying type 'float'}} 1100 // expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'F' (aka 'float')}} 1101 #endif 1102 1103 #define DECLS \ 1104 typedef int A; \ 1105 typedef double B; \ 1106 typedef I C; 1107 1108 #if defined(FIRST) || defined(SECOND) 1109 typedef int I; 1110 #endif 1111 1112 #if defined(FIRST) || defined(SECOND) 1113 struct Valid1 { 1114 DECLS 1115 }; 1116 #else 1117 Valid1 v1; 1118 #endif 1119 1120 #if defined(FIRST) || defined(SECOND) 1121 struct Invalid1 { 1122 DECLS 1123 ACCESS 1124 }; 1125 #else 1126 Invalid1 i1; 1127 // expected-error@second.h:* {{'TypeDef::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1128 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1129 #endif 1130 #undef DECLS 1131 } // namespace TypeDef 1132 1133 namespace Using { 1134 #if defined(FIRST) 1135 struct S1 { 1136 using a = int; 1137 }; 1138 #elif defined(SECOND) 1139 struct S1 { 1140 using a = double; 1141 }; 1142 #else 1143 S1 s1; 1144 // expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}} 1145 // expected-note@second.h:* {{declaration of 'a' does not match}} 1146 #endif 1147 1148 #if defined(FIRST) 1149 struct S2 { 1150 using a = int; 1151 }; 1152 #elif defined(SECOND) 1153 struct S2 { 1154 using b = int; 1155 }; 1156 #else 1157 S2 s2; 1158 // expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}} 1159 // expected-note@second.h:* {{definition has no member 'a'}} 1160 #endif 1161 1162 #if defined(FIRST) 1163 typedef int T; 1164 struct S3 { 1165 using a = T; 1166 }; 1167 #elif defined(SECOND) 1168 typedef double T; 1169 struct S3 { 1170 using a = T; 1171 }; 1172 #else 1173 S3 s3; 1174 // FIXME: We should reject the merge of `S3` due to the inconsistent definition of `T`. 1175 #endif 1176 1177 #if defined(FIRST) 1178 struct S4 { 1179 using a = int; 1180 using b = int; 1181 }; 1182 #elif defined(SECOND) 1183 struct S4 { 1184 using b = int; 1185 using a = int; 1186 }; 1187 #else 1188 S4 s4; 1189 // expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}} 1190 // expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}} 1191 #endif 1192 1193 #if defined(FIRST) 1194 struct S5 { 1195 using a = int; 1196 using b = int; 1197 int x; 1198 }; 1199 #elif defined(SECOND) 1200 struct S5 { 1201 int x; 1202 using b = int; 1203 using a = int; 1204 }; 1205 #else 1206 S5 s5; 1207 // expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} 1208 // expected-note@first.h:* {{but in 'FirstModule' found type alias}} 1209 #endif 1210 1211 #if defined(FIRST) 1212 typedef float F; 1213 struct S6 { 1214 using a = int; 1215 using b = F; 1216 }; 1217 #elif defined(SECOND) 1218 struct S6 { 1219 using a = int; 1220 using b = float; 1221 }; 1222 #else 1223 S6 s6; 1224 // expected-error@second.h:* {{'Using::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'b' with underlying type 'float'}} 1225 // expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'F' (aka 'float')}} 1226 #endif 1227 1228 #if defined(FIRST) || defined(SECOND) 1229 using I = int; 1230 #endif 1231 1232 #define DECLS \ 1233 using A = int; \ 1234 using B = double; \ 1235 using C = I; 1236 1237 #if defined(FIRST) || defined(SECOND) 1238 struct Valid1 { 1239 DECLS 1240 }; 1241 #else 1242 Valid1 v1; 1243 #endif 1244 1245 #if defined(FIRST) || defined(SECOND) 1246 struct Invalid1 { 1247 DECLS 1248 ACCESS 1249 }; 1250 #else 1251 Invalid1 i1; 1252 // expected-error@second.h:* {{'Using::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1253 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1254 #endif 1255 #undef DECLS 1256 } // namespace Using 1257 1258 namespace RecordType { 1259 #if defined(FIRST) 1260 struct B1 {}; 1261 struct S1 { 1262 B1 x; 1263 }; 1264 #elif defined(SECOND) 1265 struct A1 {}; 1266 struct S1 { 1267 A1 x; 1268 }; 1269 #else 1270 S1 s1; 1271 // expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}} 1272 // expected-note@second.h:* {{declaration of 'x' does not match}} 1273 #endif 1274 1275 #define DECLS \ 1276 Foo F; 1277 1278 #if defined(FIRST) || defined(SECOND) 1279 struct Foo {}; 1280 #endif 1281 1282 #if defined(FIRST) || defined(SECOND) 1283 struct Valid1 { 1284 DECLS 1285 }; 1286 #else 1287 Valid1 v1; 1288 #endif 1289 1290 #if defined(FIRST) || defined(SECOND) 1291 struct Invalid1 { 1292 DECLS 1293 ACCESS 1294 }; 1295 #else 1296 Invalid1 i1; 1297 // expected-error@second.h:* {{'RecordType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1298 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1299 #endif 1300 #undef DECLS 1301 } // namespace RecordType 1302 1303 namespace DependentType { 1304 #if defined(FIRST) 1305 template <class T> 1306 class S1 { 1307 typename T::typeA x; 1308 }; 1309 #elif defined(SECOND) 1310 template <class T> 1311 class S1 { 1312 typename T::typeB x; 1313 }; 1314 #else 1315 template<class T> 1316 using U1 = S1<T>; 1317 // expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}} 1318 // expected-note@second.h:* {{declaration of 'x' does not match}} 1319 #endif 1320 1321 #define DECLS \ 1322 typename T::typeA x; 1323 1324 #if defined(FIRST) || defined(SECOND) 1325 template <class T> 1326 struct Valid1 { 1327 DECLS 1328 }; 1329 #else 1330 template <class T> 1331 using V1 = Valid1<T>; 1332 #endif 1333 1334 #if defined(FIRST) || defined(SECOND) 1335 template <class T> 1336 struct Invalid1 { 1337 DECLS 1338 ACCESS 1339 }; 1340 #else 1341 template <class T> 1342 using I1 = Invalid1<T>; 1343 // expected-error@second.h:* {{'DependentType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1344 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1345 #endif 1346 #undef DECLS 1347 } // namespace DependentType 1348 1349 namespace ElaboratedType { 1350 #if defined(FIRST) 1351 namespace N1 { using type = double; } 1352 struct S1 { 1353 N1::type x; 1354 }; 1355 #elif defined(SECOND) 1356 namespace N1 { using type = int; } 1357 struct S1 { 1358 N1::type x; 1359 }; 1360 #else 1361 S1 s1; 1362 #endif 1363 1364 #define DECLS \ 1365 NS::type x; 1366 1367 #if defined(FIRST) || defined(SECOND) 1368 namespace NS { using type = float; } 1369 #endif 1370 1371 #if defined(FIRST) || defined(SECOND) 1372 struct Valid1 { 1373 DECLS 1374 }; 1375 #else 1376 Valid1 v1; 1377 #endif 1378 1379 #if defined(FIRST) || defined(SECOND) 1380 struct Invalid1 { 1381 DECLS 1382 ACCESS 1383 }; 1384 #else 1385 Invalid1 i1; 1386 // expected-error@second.h:* {{'ElaboratedType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1387 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1388 #endif 1389 #undef DECLS 1390 } // namespace ElaboratedType 1391 1392 namespace Enum { 1393 #if defined(FIRST) 1394 enum A1 {}; 1395 struct S1 { 1396 A1 x; 1397 }; 1398 #elif defined(SECOND) 1399 enum A2 {}; 1400 struct S1 { 1401 A2 x; 1402 }; 1403 #else 1404 S1 s1; 1405 // expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}} 1406 // expected-note@second.h:* {{declaration of 'x' does not match}} 1407 #endif 1408 1409 #define DECLS \ 1410 E e = E1; 1411 1412 #if defined(FIRST) || defined(SECOND) 1413 enum E { E1, E2 }; 1414 #endif 1415 1416 #if defined(FIRST) || defined(SECOND) 1417 struct Valid1 { 1418 DECLS 1419 }; 1420 #else 1421 Valid1 v1; 1422 #endif 1423 1424 #if defined(FIRST) || defined(SECOND) 1425 struct Invalid1 { 1426 DECLS 1427 ACCESS 1428 }; 1429 #else 1430 Invalid1 i1; 1431 // expected-error@second.h:* {{'Enum::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1432 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1433 #endif 1434 #undef DECLS 1435 } 1436 1437 namespace NestedNamespaceSpecifier { 1438 #if defined(FIRST) 1439 namespace LevelA1 { 1440 using Type = int; 1441 } 1442 1443 struct S1 { 1444 LevelA1::Type x; 1445 }; 1446 # elif defined(SECOND) 1447 namespace LevelB1 { 1448 namespace LevelC1 { 1449 using Type = int; 1450 } 1451 } 1452 1453 struct S1 { 1454 LevelB1::LevelC1::Type x; 1455 }; 1456 #else 1457 S1 s1; 1458 // expected-error@second.h:* {{'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')}} 1459 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}} 1460 #endif 1461 1462 #if defined(FIRST) 1463 namespace LevelA2 { using Type = int; } 1464 struct S2 { 1465 LevelA2::Type x; 1466 }; 1467 # elif defined(SECOND) 1468 struct S2 { 1469 int x; 1470 }; 1471 #else 1472 S2 s2; 1473 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}} 1474 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}} 1475 #endif 1476 1477 namespace LevelA3 { using Type = int; } 1478 namespace LevelB3 { using Type = int; } 1479 #if defined(FIRST) 1480 struct S3 { 1481 LevelA3::Type x; 1482 }; 1483 # elif defined(SECOND) 1484 struct S3 { 1485 LevelB3::Type x; 1486 }; 1487 #else 1488 S3 s3; 1489 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB3::Type' (aka 'int')}} 1490 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}} 1491 #endif 1492 1493 #if defined(FIRST) 1494 struct TA4 { using Type = int; }; 1495 struct S4 { 1496 TA4::Type x; 1497 }; 1498 # elif defined(SECOND) 1499 struct TB4 { using Type = int; }; 1500 struct S4 { 1501 TB4::Type x; 1502 }; 1503 #else 1504 S4 s4; 1505 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'TB4::Type' (aka 'int')}} 1506 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}} 1507 #endif 1508 1509 #if defined(FIRST) 1510 struct T5 { using Type = int; }; 1511 struct S5 { 1512 T5::Type x; 1513 }; 1514 # elif defined(SECOND) 1515 namespace T5 { using Type = int; }; 1516 struct S5 { 1517 T5::Type x; 1518 }; 1519 #else 1520 S5 s5; 1521 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'T5::Type' (aka 'int')}} 1522 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}} 1523 #endif 1524 1525 #if defined(FIRST) 1526 namespace N6 {using I = int;} 1527 struct S6 { 1528 NestedNamespaceSpecifier::N6::I x; 1529 }; 1530 # elif defined(SECOND) 1531 using I = int; 1532 struct S6 { 1533 ::NestedNamespaceSpecifier::I x; 1534 }; 1535 #else 1536 S6 s6; 1537 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '::NestedNamespaceSpecifier::I' (aka 'int')}} 1538 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}} 1539 #endif 1540 1541 #if defined(FIRST) 1542 template <class T, class U> 1543 class S7 { 1544 typename T::type *x = {}; 1545 int z = x->T::foo(); 1546 }; 1547 #elif defined(SECOND) 1548 template <class T, class U> 1549 class S7 { 1550 typename T::type *x = {}; 1551 int z = x->U::foo(); 1552 }; 1553 #else 1554 template <class T, class U> 1555 using U7 = S7<T, U>; 1556 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'z' with an initializer}} 1557 // expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}} 1558 #endif 1559 1560 #if defined(FIRST) 1561 template <class T> 1562 class S8 { 1563 int x = T::template X<int>::value; 1564 }; 1565 #elif defined(SECOND) 1566 template <class T> 1567 class S8 { 1568 int x = T::template Y<int>::value; 1569 }; 1570 #else 1571 template <class T> 1572 using U8 = S8<T>; 1573 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}} 1574 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}} 1575 #endif 1576 1577 #if defined(FIRST) 1578 namespace N9 { using I = int; } 1579 namespace O9 = N9; 1580 struct S9 { 1581 O9::I x; 1582 }; 1583 #elif defined(SECOND) 1584 namespace N9 { using I = int; } 1585 namespace P9 = N9; 1586 struct S9 { 1587 P9::I x; 1588 }; 1589 #else 1590 S9 s9; 1591 // expected-error@second.h:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}} 1592 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}} 1593 #endif 1594 1595 namespace N10 { 1596 #if defined(FIRST) 1597 inline namespace A { struct X {}; } 1598 struct S10 { 1599 A::X x; 1600 }; 1601 #elif defined(SECOND) 1602 inline namespace B { struct X {}; } 1603 struct S10 { 1604 B::X x; 1605 }; 1606 #else 1607 S10 s10; 1608 // expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}} 1609 // expected-note@first.h:* {{declaration of 'x' does not match}} 1610 #endif 1611 } 1612 1613 #define DECLS \ 1614 NS1::Type a; \ 1615 NS1::NS2::Type b; \ 1616 NS1::S c; \ 1617 NS3::Type d; 1618 1619 #if defined(FIRST) || defined(SECOND) 1620 namespace NS1 { 1621 using Type = int; 1622 namespace NS2 { 1623 using Type = double; 1624 } 1625 struct S {}; 1626 } 1627 namespace NS3 = NS1; 1628 #endif 1629 1630 #if defined(FIRST) || defined(SECOND) 1631 struct Valid1 { 1632 DECLS 1633 }; 1634 #else 1635 Valid1 v1; 1636 #endif 1637 1638 #if defined(FIRST) || defined(SECOND) 1639 struct Invalid1 { 1640 DECLS 1641 ACCESS 1642 }; 1643 #else 1644 Invalid1 i1; 1645 // expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1646 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1647 #endif 1648 #undef DECLS 1649 1650 #define DECLS \ 1651 typename T::type *x = {}; \ 1652 int y = x->T::foo(); \ 1653 int z = U::template X<int>::value; 1654 1655 #if defined(FIRST) || defined(SECOND) 1656 template <class T, class U> 1657 struct Valid2 { 1658 DECLS 1659 }; 1660 #else 1661 template <class T, class U> 1662 using V2 = Valid2<T, U>; 1663 #endif 1664 1665 #if defined(FIRST) || defined(SECOND) 1666 template <class T, class U> 1667 struct Invalid2 { 1668 DECLS 1669 ACCESS 1670 }; 1671 #else 1672 template <class T, class U> 1673 using I2 = Invalid2<T, U>; 1674 // expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1675 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1676 #endif 1677 #undef DECLS 1678 } // namespace NestedNamespaceSpecifier 1679 1680 namespace TemplateSpecializationType { 1681 #if defined(FIRST) 1682 template <class T1> struct U1 {}; 1683 struct S1 { 1684 U1<int> u; 1685 }; 1686 #elif defined(SECOND) 1687 template <class T1, class T2> struct U1 {}; 1688 struct S1 { 1689 U1<int, int> u; 1690 }; 1691 #else 1692 S1 s1; 1693 // expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}} 1694 // expected-note@second.h:* {{declaration of 'u' does not match}} 1695 #endif 1696 1697 #if defined(FIRST) 1698 template <class T1> struct U2 {}; 1699 struct S2 { 1700 U2<int> u; 1701 }; 1702 #elif defined(SECOND) 1703 template <class T1> struct V1 {}; 1704 struct S2 { 1705 V1<int> u; 1706 }; 1707 #else 1708 S2 s2; 1709 // expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}} 1710 // expected-note@second.h:* {{declaration of 'u' does not match}} 1711 #endif 1712 1713 #define DECLS \ 1714 OneTemplateArg<int> x; \ 1715 OneTemplateArg<double> y; \ 1716 OneTemplateArg<char *> z; \ 1717 TwoTemplateArgs<int, int> a; \ 1718 TwoTemplateArgs<double, float> b; \ 1719 TwoTemplateArgs<short *, char> c; 1720 1721 #if defined(FIRST) || defined(SECOND) 1722 template <class T> struct OneTemplateArg {}; 1723 template <class T, class U> struct TwoTemplateArgs {}; 1724 #endif 1725 1726 #if defined(FIRST) || defined(SECOND) 1727 struct Valid1 { 1728 DECLS 1729 }; 1730 #else 1731 Valid1 v1; 1732 #endif 1733 1734 #if defined(FIRST) || defined(SECOND) 1735 struct Invalid1 { 1736 DECLS 1737 ACCESS 1738 }; 1739 #else 1740 Invalid1 i1; 1741 // expected-error@second.h:* {{'TemplateSpecializationType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 1742 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 1743 #endif 1744 #undef DECLS 1745 } // namespace TemplateSpecializationType 1746 1747 namespace TemplateArgument { 1748 #if defined(FIRST) 1749 template <class> struct U1{}; 1750 struct S1 { 1751 U1<int> x; 1752 }; 1753 #elif defined(SECOND) 1754 template <int> struct U1{}; 1755 struct S1 { 1756 U1<1> x; 1757 }; 1758 #else 1759 S1 s1; 1760 // expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}} 1761 // expected-note@second.h:* {{declaration of 'x' does not match}} 1762 #endif 1763 1764 #if defined(FIRST) 1765 template <int> struct U2{}; 1766 struct S2 { 1767 using T = U2<2>; 1768 }; 1769 #elif defined(SECOND) 1770 template <int> struct U2{}; 1771 struct S2 { 1772 using T = U2<(2)>; 1773 }; 1774 #else 1775 S2 s2; 1776 // expected-error@second.h:* {{'TemplateArgument::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U2<(2)>'}} 1777 // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}} 1778 #endif 1779 1780 #if defined(FIRST) 1781 template <int> struct U3{}; 1782 struct S3 { 1783 using T = U3<2>; 1784 }; 1785 #elif defined(SECOND) 1786 template <int> struct U3{}; 1787 struct S3 { 1788 using T = U3<1 + 1>; 1789 }; 1790 #else 1791 S3 s3; 1792 // expected-error@second.h:* {{'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>'}} 1793 // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}} 1794 #endif 1795 1796 #if defined(FIRST) 1797 template<class> struct T4a {}; 1798 template <template <class> class T> struct U4 {}; 1799 struct S4 { 1800 U4<T4a> x; 1801 }; 1802 #elif defined(SECOND) 1803 template<class> struct T4b {}; 1804 template <template <class> class T> struct U4 {}; 1805 struct S4 { 1806 U4<T4b> x; 1807 }; 1808 #else 1809 S4 s4; 1810 // expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}} 1811 // expected-note@second.h:* {{declaration of 'x' does not match}} 1812 #endif 1813 1814 #if defined(FIRST) 1815 template <class T> struct U5 {}; 1816 struct S5 { 1817 U5<int> x; 1818 }; 1819 #elif defined(SECOND) 1820 template <class T> struct U5 {}; 1821 struct S5 { 1822 U5<short> x; 1823 }; 1824 #else 1825 S5 s5; 1826 // expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}} 1827 // expected-note@second.h:* {{declaration of 'x' does not match}} 1828 #endif 1829 1830 #if defined(FIRST) 1831 template <class T> struct U6 {}; 1832 struct S6 { 1833 U6<int> x; 1834 U6<short> y; 1835 }; 1836 #elif defined(SECOND) 1837 template <class T> struct U6 {}; 1838 struct S6 { 1839 U6<short> y; 1840 U6<int> x; 1841 }; 1842 #else 1843 S6 s6; 1844 // expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} 1845 // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}} 1846 #endif 1847 1848 #if defined(FIRST) 1849 struct S7 { 1850 template<int> void run() {} 1851 template<> void run<1>() {} 1852 }; 1853 #elif defined(SECOND) 1854 struct S7 { 1855 template<int> void run() {} 1856 void run() {} 1857 }; 1858 #else 1859 S7 s7; 1860 // expected-error@second.h:* {{'TemplateArgument::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with no template arguments}} 1861 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with template arguments}} 1862 #endif 1863 1864 #if defined(FIRST) 1865 struct S8 { 1866 static int a, b; 1867 template<int&> void run() {} 1868 template<int&, int&> void run() {} 1869 template<> void run<a>() {} 1870 }; 1871 #elif defined(SECOND) 1872 struct S8 { 1873 static int a, b; 1874 template<int&> void run() {} 1875 template<int&, int&> void run() {} 1876 template<> void run<a, b>() {} 1877 }; 1878 #else 1879 S8 s8; 1880 // expected-error@second.h:* {{'TemplateArgument::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 2 template arguments}} 1881 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 1 template argument}} 1882 #endif 1883 1884 #if defined(FIRST) 1885 struct S9 { 1886 static int a, b; 1887 template<int&> void run() {} 1888 template<> void run<a>() {} 1889 }; 1890 #elif defined(SECOND) 1891 struct S9 { 1892 static int a, b; 1893 template<int&> void run() {} 1894 template<> void run<b>() {} 1895 }; 1896 #else 1897 S9 s9; 1898 // expected-error@second.h:* {{'TemplateArgument::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 'b' for 1st template argument}} 1899 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 1st template argument}} 1900 #endif 1901 1902 #if defined(FIRST) 1903 struct S10 { 1904 static int a, b; 1905 template<int, int&...> void run() {} 1906 template<> void run<1, a>() {} 1907 }; 1908 #elif defined(SECOND) 1909 struct S10 { 1910 static int a, b; 1911 template<int, int&...> void run() {} 1912 template<> void run<1, b>() {} 1913 }; 1914 #else 1915 S10 s10; 1916 // expected-error@second.h:* {{'TemplateArgument::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 'b' for 2nd template argument}} 1917 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 2nd template argument}} 1918 #endif 1919 1920 #if defined(FIRST) 1921 struct S11 { 1922 static int a, b; 1923 template<int, int&...> void run() {} 1924 template<> void run<1, a>() {} 1925 }; 1926 #elif defined(SECOND) 1927 struct S11 { 1928 static int a, b; 1929 template<int, int&...> void run() {} 1930 template<> void run<1, a, a>() {} 1931 }; 1932 #else 1933 S11 s11; 1934 // expected-error@second.h:* {{'TemplateArgument::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 3 template arguments}} 1935 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 2 template arguments}} 1936 #endif 1937 1938 #if defined(FIRST) 1939 struct S12 { 1940 template <int> void f(){}; 1941 template <> void f<1>(){}; 1942 }; 1943 #elif defined(SECOND) 1944 struct S12 { 1945 template <int> void f(){}; 1946 template <> void f<2>(){}; 1947 }; 1948 #else 1949 S12 s12; 1950 // expected-error@second.h:* {{'TemplateArgument::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 2 for 1st template argument}} 1951 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 1 for 1st template argument}} 1952 #endif 1953 1954 #if defined(FIRST) 1955 struct S13 { 1956 template <int> void f(){}; 1957 template <> void f<10>(){}; 1958 }; 1959 #elif defined(SECOND) 1960 struct S13 { 1961 template <int> void f(){}; 1962 template <> void f<10>(){}; 1963 }; 1964 #else 1965 S13 s13; 1966 #endif 1967 1968 #if defined(FIRST) 1969 struct S14 { 1970 template <bool, bool> void f(){}; 1971 template <> void f<true, false>(){}; 1972 }; 1973 #elif defined(SECOND) 1974 struct S14 { 1975 template <bool, bool> void f(){}; 1976 template <> void f<false, true>(){}; 1977 }; 1978 #else 1979 S14 s14; 1980 // expected-error@second.h:* {{'TemplateArgument::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 0 for 1st template argument}} 1981 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 1 for 1st template argument}} 1982 #endif 1983 1984 #if defined(FIRST) 1985 struct S15 { 1986 template <bool, bool> void f(){}; 1987 template <> void f<true, true>(){}; 1988 }; 1989 #elif defined(SECOND) 1990 struct S15 { 1991 template <bool, bool> void f(){}; 1992 template <> void f<true, true>(){}; 1993 }; 1994 #else 1995 S15 s15; 1996 #endif 1997 1998 #if defined(FIRST) 1999 struct S16 { 2000 template <int *> void f(){}; 2001 template <> void f<nullptr>(){}; 2002 }; 2003 #elif defined(SECOND) 2004 struct S16 { 2005 template <int *> void f(){}; 2006 template <> void f<nullptr>(){}; 2007 }; 2008 #else 2009 S16 s16; 2010 #endif 2011 2012 #if defined(FIRST) 2013 struct S17 { 2014 static int x; 2015 template <int *> void f(){}; 2016 template <> void f<&x>(){}; 2017 }; 2018 #elif defined(SECOND) 2019 struct S17 { 2020 static int x; 2021 template <int *> void f(){}; 2022 template <> void f<nullptr>(){}; 2023 }; 2024 #else 2025 S17 s17; 2026 // expected-error@second.h:* {{'TemplateArgument::S17' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with nullptr for 1st template argument}} 2027 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 'x' for 1st template argument}} 2028 #endif 2029 2030 #if defined(FIRST) 2031 struct S18 { 2032 static int x; 2033 template <int *> void f(){}; 2034 template <> void f<&x>(){}; 2035 }; 2036 #elif defined(SECOND) 2037 struct S18 { 2038 static int x; 2039 template <int *> void f(){}; 2040 template <> void f<&x>(){}; 2041 }; 2042 #else 2043 S18 s18; 2044 #endif 2045 2046 #if defined(FIRST) 2047 struct S19 { 2048 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1); 2049 template <_BitInt(128)> void f(){}; 2050 template <> void f<x + x>(){}; 2051 }; 2052 #elif defined(SECOND) 2053 struct S19 { 2054 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1); 2055 template <_BitInt(128)> void f(){}; 2056 template <> void f<x + x>(){}; 2057 }; 2058 #else 2059 S19 s19; 2060 #endif 2061 2062 #if defined(FIRST) 2063 struct S20 { 2064 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1); 2065 template <_BitInt(128)> void f(){}; 2066 template <> void f<x + x>(){}; 2067 }; 2068 #elif defined(SECOND) 2069 struct S20 { 2070 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1); 2071 template <_BitInt(128)> void f(){}; 2072 template <> void f<x>(){}; 2073 }; 2074 #else 2075 S20 s20; 2076 // expected-error@second.h:* {{'TemplateArgument::S20' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 18446744073709551615 for 1st template argument}} 2077 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 36893488147419103230 for 1st template argument}} 2078 #endif 2079 2080 #if defined(FIRST) 2081 struct S21 { 2082 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1); 2083 template <_BitInt(128)> void f(){}; 2084 template <> void f<x + 0>(){}; 2085 }; 2086 #elif defined(SECOND) 2087 struct S21 { 2088 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1); 2089 template <_BitInt(128)> void f(){}; 2090 template <> void f<(unsigned long long)-1>(){}; 2091 }; 2092 #else 2093 S21 s21; 2094 #endif 2095 2096 #if defined(FIRST) 2097 struct S22 { 2098 template <double> void f(){}; 2099 template <> void f<1.5>(){}; 2100 }; 2101 #elif defined(SECOND) 2102 struct S22 { 2103 template <double> void f(){}; 2104 template <> void f<1.7>(){}; 2105 }; 2106 #else 2107 S22 s22; 2108 // expected-error@second.h:* {{'TemplateArgument::S22' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 1.700000e+00 for 1st template argument}} 2109 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 1.500000e+00 for 1st template argument}} 2110 #endif 2111 2112 #if defined(FIRST) 2113 struct S23 { 2114 template <double> void f(){}; 2115 template <> void f<2.7>(){}; 2116 }; 2117 #elif defined(SECOND) 2118 struct S23 { 2119 template <double> void f(){}; 2120 template <> void f<2.7>(){}; 2121 }; 2122 #else 2123 S23 s23; 2124 #endif 2125 2126 #if defined(FIRST) || defined(SECOND) 2127 struct Composite { 2128 int n1[4]; 2129 int n2[4]; 2130 }; 2131 extern Composite composite; 2132 #endif 2133 2134 #if defined(FIRST) 2135 struct S24 { 2136 template <int&> void f(){}; 2137 template <> void f<composite.n1[1]>(){}; 2138 }; 2139 #elif defined(SECOND) 2140 struct S24 { 2141 template <int&> void f(){}; 2142 template <> void f<composite.n1[2]>(){}; 2143 }; 2144 #else 2145 S24 s24; 2146 // expected-error@second.h:* {{'TemplateArgument::S24' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with composite.n1[2] for 1st template argument}} 2147 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with composite.n1[1] for 1st template argument}} 2148 #endif 2149 2150 #if defined(FIRST) || defined(SECOND) 2151 struct S25 { 2152 template <int&> void f(); 2153 template <> void f<composite.n1[2]>(); 2154 }; 2155 #else 2156 S25 s25; 2157 #endif 2158 2159 #if defined(FIRST) 2160 struct S26 { 2161 template <int*> void f(){}; 2162 template <> void f<&composite.n1[4]>(){}; // Past-the-end pointer. 2163 }; 2164 #elif defined(SECOND) 2165 struct S26 { 2166 template <int*> void f(){}; 2167 template <> void f<&composite.n2[0]>(){}; 2168 }; 2169 #else 2170 S26 s26; 2171 // expected-error@second.h:* {{'TemplateArgument::S26' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with &composite.n2[0] for 1st template argument}} 2172 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with &composite.n1[4] for 1st template argument}} 2173 #endif 2174 2175 #if defined(FIRST) || defined(SECOND) 2176 union Union { 2177 int i1; 2178 int i2; 2179 }; 2180 extern Union u; 2181 #endif 2182 2183 #if defined(FIRST) 2184 struct S27 { 2185 template <int&> void f(){}; 2186 template <> void f<u.i1>(){}; 2187 }; 2188 #elif defined(SECOND) 2189 struct S27 { 2190 template <int&> void f(){}; 2191 template <> void f<u.i2>(){}; 2192 }; 2193 #else 2194 S27 s27; 2195 // expected-error@second.h:* {{'TemplateArgument::S27' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with u.i2 for 1st template argument}} 2196 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with u.i1 for 1st template argument}} 2197 #endif 2198 2199 #if defined(FIRST) || defined(SECOND) 2200 struct S28 { 2201 template <int&> void f(){}; 2202 template <> void f<u.i1>(){}; 2203 }; 2204 #else 2205 S28 s28; 2206 #endif 2207 2208 #if defined(FIRST) || defined(SECOND) 2209 struct A { 2210 int a; 2211 }; 2212 struct B : A {}; 2213 struct C : A {}; 2214 struct D : B, C {}; 2215 #endif 2216 2217 #if defined(FIRST) 2218 struct S29 { 2219 template <int D::*> void f(){}; 2220 template <> void f<(int D::*)(int B::*)&A::a>(){}; 2221 }; 2222 #elif defined(SECOND) 2223 struct S29 { 2224 template <int D::*> void f(){}; 2225 template <> void f<(int D::*)(int C::*)&A::a>(){}; 2226 }; 2227 #else 2228 S29 s29; 2229 // expected-error@second.h:* {{'TemplateArgument::S29' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with &A::a for 1st template argument}} 2230 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with &A::a for 1st template argument}} 2231 #endif 2232 2233 #if defined(FIRST) || defined(SECOND) 2234 struct S30 { 2235 template <int D::*> void f(){}; 2236 template <> void f<(int D::*)(int B::*)&A::a>(){}; 2237 }; 2238 #else 2239 S30 s30; 2240 #endif 2241 2242 #if defined(FIRST) 2243 struct S31 { 2244 template <auto*> void f(){}; 2245 template <> void f<&composite.n1[2]>(){}; 2246 }; 2247 #elif defined(SECOND) 2248 struct S31 { 2249 template <auto*> void f(){}; 2250 template <> void f<(void*)&composite.n1[2]>(){}; 2251 }; 2252 #else 2253 S31 s31; 2254 // expected-error@second.h:* {{'TemplateArgument::S31' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with &composite.n1[2] for 1st template argument}} 2255 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with &composite.n1[2] for 1st template argument}} 2256 #endif 2257 2258 #if defined(FIRST) 2259 struct S32 { 2260 template <int*> void f(){}; 2261 template <> void f<__builtin_constant_p(0) ? (int*)1 : (int*)1>(){}; 2262 }; 2263 #elif defined(SECOND) 2264 struct S32 { 2265 template <int*> void f(){}; 2266 template <> void f<__builtin_constant_p(0) ? (int*)2 : (int*)2>(){}; 2267 }; 2268 #else 2269 S32 s32; 2270 // expected-error@second.h:* {{'TemplateArgument::S32' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with (int *)2 for 1st template argument}} 2271 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with (int *)1 for 1st template argument}} 2272 #endif 2273 2274 #if defined(FIRST) || defined(SECOND) 2275 struct S33 { 2276 template <int*> void f(){}; 2277 template <> void f<__builtin_constant_p(0) ? (int*)1 : (int*)1>(){}; 2278 }; 2279 #else 2280 S33 s33; 2281 #endif 2282 2283 #define DECLS \ 2284 OneClass<int> a; \ 2285 OneInt<1> b; \ 2286 using c = OneClass<float>; \ 2287 using d = OneInt<2>; \ 2288 using e = OneInt<2 + 2>; \ 2289 OneTemplateClass<OneClass> f; \ 2290 OneTemplateInt<OneInt> g; \ 2291 static int i1, i2; \ 2292 template <int &> \ 2293 void Function() {} \ 2294 template <int &, int &> \ 2295 void Function() {} \ 2296 template <> \ 2297 void Function<i1>() {} \ 2298 template <> \ 2299 void Function<i2>() {} \ 2300 template <> \ 2301 void Function<i1, i2>() {} \ 2302 template <> \ 2303 void Function<i2, i1>() {} 2304 2305 #if defined(FIRST) || defined(SECOND) 2306 template <class> struct OneClass{}; 2307 template <int> struct OneInt{}; 2308 template <template <class> class> struct OneTemplateClass{}; 2309 template <template <int> class> struct OneTemplateInt{}; 2310 #endif 2311 2312 #if defined(FIRST) || defined(SECOND) 2313 struct Valid1 { 2314 DECLS 2315 }; 2316 #else 2317 Valid1 v1; 2318 #endif 2319 2320 #if defined(FIRST) || defined(SECOND) 2321 struct Invalid1 { 2322 DECLS 2323 ACCESS 2324 }; 2325 #else 2326 Invalid1 i1; 2327 // expected-error@second.h:* {{'TemplateArgument::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 2328 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 2329 #endif 2330 #undef DECLS 2331 } // namespace TemplateArgument 2332 2333 namespace TemplateTypeParmType { 2334 #if defined(FIRST) 2335 template <class T1, class T2> 2336 struct S1 { 2337 T1 x; 2338 }; 2339 #elif defined(SECOND) 2340 template <class T1, class T2> 2341 struct S1 { 2342 T2 x; 2343 }; 2344 #else 2345 using TemplateTypeParmType::S1; 2346 // expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}} 2347 // expected-note@second.h:* {{declaration of 'x' does not match}} 2348 #endif 2349 2350 #if defined(FIRST) 2351 template <int ...Ts> 2352 struct U2 {}; 2353 template <int T, int U> 2354 class S2 { 2355 typedef U2<U, T> type; 2356 type x; 2357 }; 2358 #elif defined(SECOND) 2359 template <int ...Ts> 2360 struct U2 {}; 2361 template <int T, int U> 2362 class S2 { 2363 typedef U2<T, U> type; 2364 type x; 2365 }; 2366 #else 2367 using TemplateTypeParmType::S2; 2368 // expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}} 2369 // expected-note@second.h:* {{declaration of 'x' does not match}} 2370 // expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}} 2371 // expected-note@second.h:* {{declaration of 'type' does not match}} 2372 #endif 2373 2374 #define DECLS \ 2375 T t; \ 2376 U u; \ 2377 ParameterPack<T> a; \ 2378 ParameterPack<T, U> b; \ 2379 ParameterPack<U> c; \ 2380 ParameterPack<U, T> d; 2381 2382 #if defined(FIRST) || defined(SECOND) 2383 template <class ...Ts> struct ParameterPack {}; 2384 #endif 2385 2386 #if defined(FIRST) || defined(SECOND) 2387 template <class T, class U> 2388 struct Valid1 { 2389 DECLS 2390 }; 2391 #else 2392 using TemplateTypeParmType::Valid1; 2393 #endif 2394 2395 #if defined(FIRST) || defined(SECOND) 2396 template <class T, class U> 2397 struct Invalid1 { 2398 DECLS 2399 ACCESS 2400 }; 2401 #else 2402 using TemplateTypeParmType::Invalid1; 2403 // expected-error@second.h:* {{'TemplateTypeParmType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 2404 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 2405 #endif 2406 #undef DECLS 2407 } // namespace TemplateTypeParmType 2408 2409 namespace VarDecl { 2410 #if defined(FIRST) 2411 struct S1 { 2412 static int x; 2413 static int y; 2414 }; 2415 #elif defined(SECOND) 2416 struct S1 { 2417 static int y; 2418 static int x; 2419 }; 2420 #else 2421 S1 s1; 2422 // expected-error@second.h:* {{'VarDecl::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member with name 'y'}} 2423 // expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}} 2424 #endif 2425 2426 #if defined(FIRST) 2427 struct S2 { 2428 static int x; 2429 }; 2430 #elif defined(SECOND) 2431 using I = int; 2432 struct S2 { 2433 static I x; 2434 }; 2435 #else 2436 S2 s2; 2437 // expected-error@second.h:* {{'VarDecl::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with type 'I' (aka 'int')}} 2438 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}} 2439 #endif 2440 2441 #if defined(FIRST) 2442 struct S3 { 2443 static const int x = 1; 2444 }; 2445 #elif defined(SECOND) 2446 struct S3 { 2447 static const int x; 2448 }; 2449 #else 2450 S3 s3; 2451 // expected-error@second.h:* {{'VarDecl::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with an initializer}} 2452 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}} 2453 #endif 2454 2455 #if defined(FIRST) 2456 struct S4 { 2457 static const int x = 1; 2458 }; 2459 #elif defined(SECOND) 2460 struct S4 { 2461 static const int x = 2; 2462 }; 2463 #else 2464 S4 s4; 2465 // expected-error@second.h:* {{'VarDecl::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with an initializer}} 2466 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}} 2467 #endif 2468 2469 #if defined(FIRST) 2470 struct S5 { 2471 static const int x = 1; 2472 }; 2473 #elif defined(SECOND) 2474 struct S5 { 2475 static constexpr int x = 1; 2476 }; 2477 #else 2478 S5 s5; 2479 // expected-error@second.h:* {{'VarDecl::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' is not constexpr}} 2480 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}} 2481 #endif 2482 2483 #if defined(FIRST) 2484 struct S6 { 2485 static const int x = 1; 2486 }; 2487 #elif defined(SECOND) 2488 struct S6 { 2489 static const int y = 1; 2490 }; 2491 #else 2492 S6 s6; 2493 // expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}} 2494 // expected-note@second.h:* {{definition has no member 'x'}} 2495 #endif 2496 2497 #if defined(FIRST) 2498 struct S7 { 2499 static const int x = 1; 2500 }; 2501 #elif defined(SECOND) 2502 struct S7 { 2503 static const unsigned x = 1; 2504 }; 2505 #else 2506 S7 s7; 2507 // expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}} 2508 // expected-note@second.h:* {{declaration of 'x' does not match}} 2509 #endif 2510 2511 #if defined(FIRST) 2512 struct S8 { 2513 public: 2514 static const int x = 1; 2515 }; 2516 #elif defined(SECOND) 2517 struct S8 { 2518 static const int x = 1; 2519 public: 2520 }; 2521 #else 2522 S8 s8; 2523 // expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}} 2524 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 2525 #endif 2526 2527 #if defined(FIRST) 2528 struct S9 { 2529 static const int x = 1; 2530 }; 2531 #elif defined(SECOND) 2532 struct S9 { 2533 static int x; 2534 }; 2535 #else 2536 S9 s9; 2537 // expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}} 2538 // expected-note@second.h:* {{declaration of 'x' does not match}} 2539 #endif 2540 2541 #define DECLS \ 2542 static int a; \ 2543 static I b; \ 2544 static const int c = 1; \ 2545 static constexpr int d = 5; 2546 2547 #if defined(FIRST) || defined(SECOND) 2548 using I = int; 2549 #endif 2550 2551 #if defined(FIRST) || defined(SECOND) 2552 struct Valid1 { 2553 DECLS 2554 }; 2555 #else 2556 Valid1 v1; 2557 #endif 2558 2559 #if defined(FIRST) || defined(SECOND) 2560 struct Invalid1 { 2561 DECLS 2562 ACCESS 2563 }; 2564 #else 2565 Invalid1 i1; 2566 // expected-error@second.h:* {{'VarDecl::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 2567 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 2568 #endif 2569 #undef DECLS 2570 } // namespace VarDecl 2571 2572 namespace Friend { 2573 #if defined(FIRST) 2574 struct T1 {}; 2575 struct S1 { 2576 friend class T1; 2577 }; 2578 #elif defined(SECOND) 2579 struct T1 {}; 2580 struct S1 { 2581 friend T1; 2582 }; 2583 #else 2584 S1 s1; 2585 // expected-error@second.h:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'T1'}} 2586 // expected-note@first.h:* {{but in 'FirstModule' found friend 'class T1'}} 2587 #endif 2588 2589 #if defined(FIRST) 2590 struct T2 {}; 2591 struct S2 { 2592 friend class T2; 2593 }; 2594 #elif defined(SECOND) 2595 struct T2 {}; 2596 struct S2 { 2597 friend struct T2; 2598 }; 2599 #else 2600 S2 s2; 2601 // expected-error@second.h:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}} 2602 // expected-note@first.h:* {{but in 'FirstModule' found friend 'class T2'}} 2603 #endif 2604 2605 #if defined(FIRST) 2606 struct T4 {}; 2607 struct S4 { 2608 friend T4; 2609 }; 2610 #elif defined(SECOND) 2611 struct S4 { 2612 friend void T4(); 2613 }; 2614 #else 2615 S4 s4; 2616 // expected-error@second.h:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}} 2617 // expected-note@first.h:* {{but in 'FirstModule' found friend class}} 2618 #endif 2619 2620 #if defined(FIRST) 2621 struct S5 { 2622 friend void T5a(); 2623 }; 2624 #elif defined(SECOND) 2625 struct S5 { 2626 friend void T5b(); 2627 }; 2628 #else 2629 S5 s5; 2630 // expected-error@second.h:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}} 2631 // expected-note@first.h:* {{but in 'FirstModule' found friend function 'T5a'}} 2632 #endif 2633 2634 #define DECLS \ 2635 friend class FriendA; \ 2636 friend struct FriendB; \ 2637 friend FriendC; \ 2638 friend void Function(); 2639 2640 #if defined(FIRST) || defined(SECOND) 2641 class FriendA {}; 2642 class FriendB {}; 2643 class FriendC {}; 2644 #endif 2645 2646 #if defined(FIRST) || defined(SECOND) 2647 struct Valid1 { 2648 DECLS 2649 }; 2650 #else 2651 Valid1 v1; 2652 #endif 2653 2654 #if defined(FIRST) || defined(SECOND) 2655 struct Invalid1 { 2656 DECLS 2657 ACCESS 2658 }; 2659 #else 2660 Invalid1 i1; 2661 // expected-error@second.h:* {{'Friend::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 2662 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 2663 #endif 2664 #undef DECLS 2665 } // namespace Friend 2666 2667 namespace TemplateParameters { 2668 #if defined(FIRST) 2669 template <class A> 2670 struct S1 {}; 2671 #elif defined(SECOND) 2672 template <class B> 2673 struct S1 {}; 2674 #else 2675 using TemplateParameters::S1; 2676 // expected-error@second.h:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}} 2677 // expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}} 2678 #endif 2679 2680 #if defined(FIRST) 2681 template <class A = double> 2682 struct S2 {}; 2683 #elif defined(SECOND) 2684 template <class A = int> 2685 struct S2 {}; 2686 #else 2687 using TemplateParameters::S2; 2688 // expected-error@second.h:* {{'TemplateParameters::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 2689 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}} 2690 #endif 2691 2692 #if defined(FIRST) 2693 template <class A = int> 2694 struct S3 {}; 2695 #elif defined(SECOND) 2696 template <class A> 2697 struct S3 {}; 2698 #else 2699 using TemplateParameters::S3; 2700 // expected-error@second.h:* {{'TemplateParameters::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with no default argument}} 2701 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with default argument}} 2702 #endif 2703 2704 #if defined(FIRST) 2705 template <int A> 2706 struct S4 {}; 2707 #elif defined(SECOND) 2708 template <int A = 2> 2709 struct S4 {}; 2710 #else 2711 using TemplateParameters::S4; 2712 // expected-error@second.h:* {{'TemplateParameters::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 2713 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with no default argument}} 2714 #endif 2715 2716 #if defined(FIRST) 2717 template <int> class S5_first {}; 2718 template <template<int> class A = S5_first> 2719 struct S5 {}; 2720 #elif defined(SECOND) 2721 template <int> class S5_second {}; 2722 template <template<int> class A = S5_second> 2723 struct S5 {}; 2724 #else 2725 using TemplateParameters::S5; 2726 // expected-error@second.h:* {{'TemplateParameters::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 2727 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}} 2728 #endif 2729 2730 #if defined(FIRST) 2731 template <class A> 2732 struct S6 {}; 2733 #elif defined(SECOND) 2734 template <class> 2735 struct S6 {}; 2736 #else 2737 using TemplateParameters::S6; 2738 // expected-error@second.h:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}} 2739 // expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}} 2740 #endif 2741 2742 #if defined(FIRST) 2743 template <int A = 7> 2744 struct S7 {}; 2745 #elif defined(SECOND) 2746 template <int A = 8> 2747 struct S7 {}; 2748 #else 2749 using TemplateParameters::S7; 2750 // expected-error@second.h:* {{'TemplateParameters::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 2751 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}} 2752 #endif 2753 2754 #if defined(FIRST) 2755 template <int* A = nullptr> 2756 struct S8 {}; 2757 #elif defined(SECOND) 2758 inline int S8_default_arg = 0x12345; 2759 template <int* A = &S8_default_arg> 2760 struct S8 {}; 2761 #else 2762 using TemplateParameters::S8; 2763 // expected-error@second.h:* {{'TemplateParameters::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}} 2764 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}} 2765 #endif 2766 2767 #if defined(FIRST) 2768 template <int A = 43> 2769 struct S9 {}; 2770 #elif defined(SECOND) 2771 template <int A = 43> 2772 struct S9 {}; 2773 #else 2774 using TemplateParameters::S9; 2775 #endif 2776 2777 #if defined(FIRST) 2778 template <class A = double> 2779 struct S10 {}; 2780 #elif defined(SECOND) 2781 template <class A = double> 2782 struct S10 {}; 2783 #else 2784 using TemplateParameters::S10; 2785 #endif 2786 2787 #if defined(FIRST) 2788 template <template<int> class A = S9> 2789 struct S11 {}; 2790 #elif defined(SECOND) 2791 template <template<int> class A = S9> 2792 struct S11 {}; 2793 #else 2794 using TemplateParameters::S11; 2795 #endif 2796 2797 // FIXME: It looks like we didn't implement ODR check for template variables. 2798 // S12, S13 and S14 show this. 2799 #if defined(FIRST) 2800 template <int A = 43> 2801 int S12 {}; 2802 #elif defined(SECOND) 2803 template <int A = 44> 2804 int S12 {}; 2805 #else 2806 using TemplateParameters::S12; 2807 #endif 2808 2809 #if defined(FIRST) 2810 template <class A = double> 2811 int S13 {}; 2812 #elif defined(SECOND) 2813 template <class A = int> 2814 int S13 {}; 2815 #else 2816 using TemplateParameters::S13; 2817 #endif 2818 2819 #if defined(FIRST) 2820 template <class A> 2821 int S14 {}; 2822 #elif defined(SECOND) 2823 template <class B> 2824 int S14 {}; 2825 #else 2826 using TemplateParameters::S14; 2827 #endif 2828 2829 #define DECLS 2830 2831 #if defined(FIRST) || defined(SECOND) 2832 template <class> class DefaultArg; 2833 #endif 2834 2835 #if defined(FIRST) || defined(SECOND) 2836 template <int, class, template <class> class, 2837 int A, class B, template <int> class C, 2838 int D = 1, class E = int, template <class F> class = DefaultArg> 2839 struct Valid1 { 2840 DECLS 2841 }; 2842 #else 2843 using TemplateParameters::Valid1; 2844 #endif 2845 2846 #if defined(FIRST) || defined(SECOND) 2847 template <int, class, template <class> class, 2848 int A, class B, template <int> class C, 2849 int D = 1, class E = int, template <class F> class = DefaultArg> 2850 struct Invalid1 { 2851 DECLS 2852 ACCESS 2853 }; 2854 #else 2855 using TemplateParameters::Invalid1; 2856 // expected-error@second.h:* {{'TemplateParameters::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 2857 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 2858 #endif 2859 #undef DECLS 2860 } // namespace TemplateParameters 2861 2862 namespace BaseClass { 2863 #if defined(FIRST) 2864 struct B1 {}; 2865 struct S1 : B1 {}; 2866 #elif defined(SECOND) 2867 struct S1 {}; 2868 #else 2869 S1 s1; 2870 // expected-error@second.h:* {{'BaseClass::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 base classes}} 2871 // expected-note@first.h:* {{but in 'FirstModule' found 1 base class}} 2872 #endif 2873 2874 #if defined(FIRST) 2875 struct S2 {}; 2876 #elif defined(SECOND) 2877 struct B2 {}; 2878 struct S2 : virtual B2 {}; 2879 #else 2880 S2 s2; 2881 // expected-error@second.h:* {{'BaseClass::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 base class}} 2882 // expected-note@first.h:* {{but in 'FirstModule' found 0 base classes}} 2883 #endif 2884 2885 #if defined(FIRST) 2886 struct B3a {}; 2887 struct S3 : B3a {}; 2888 #elif defined(SECOND) 2889 struct B3b {}; 2890 struct S3 : virtual B3b {}; 2891 #else 2892 S3 s3; 2893 // expected-error@second.h:* {{'BaseClass::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}} 2894 // expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}} 2895 #endif 2896 2897 #if defined(FIRST) 2898 struct B4a {}; 2899 struct S4 : B4a {}; 2900 #elif defined(SECOND) 2901 struct B4b {}; 2902 struct S4 : B4b {}; 2903 #else 2904 S4 s4; 2905 // expected-error@second.h:* {{'BaseClass::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class with type 'B4b'}} 2906 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class with different type 'B4a'}} 2907 #endif 2908 2909 #if defined(FIRST) 2910 struct B5a {}; 2911 struct S5 : virtual B5a {}; 2912 #elif defined(SECOND) 2913 struct B5a {}; 2914 struct S5 : B5a {}; 2915 #else 2916 S5 s5; 2917 // expected-error@second.h:* {{'BaseClass::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 virtual base classes}} 2918 // expected-note@first.h:* {{but in 'FirstModule' found 1 virtual base class}} 2919 #endif 2920 2921 #if defined(FIRST) 2922 struct B6a {}; 2923 struct S6 : B6a {}; 2924 #elif defined(SECOND) 2925 struct B6a {}; 2926 struct S6 : virtual B6a {}; 2927 #else 2928 S6 s6; 2929 // expected-error@second.h:* {{'BaseClass::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}} 2930 // expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}} 2931 #endif 2932 2933 #if defined(FIRST) 2934 struct B7a {}; 2935 struct S7 : protected B7a {}; 2936 #elif defined(SECOND) 2937 struct B7a {}; 2938 struct S7 : B7a {}; 2939 #else 2940 S7 s7; 2941 // expected-error@second.h:* {{'BaseClass::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B7a' with no access specifier}} 2942 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B7a' with protected access specifier}} 2943 #endif 2944 2945 #if defined(FIRST) 2946 struct B8a {}; 2947 struct S8 : public B8a {}; 2948 #elif defined(SECOND) 2949 struct B8a {}; 2950 struct S8 : private B8a {}; 2951 #else 2952 S8 s8; 2953 // expected-error@second.h:* {{'BaseClass::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B8a' with private access specifier}} 2954 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B8a' with public access specifier}} 2955 #endif 2956 2957 #if defined(FIRST) 2958 struct B9a {}; 2959 struct S9 : private B9a {}; 2960 #elif defined(SECOND) 2961 struct B9a {}; 2962 struct S9 : public B9a {}; 2963 #else 2964 S9 s9; 2965 // expected-error@second.h:* {{'BaseClass::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B9a' with public access specifier}} 2966 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B9a' with private access specifier}} 2967 #endif 2968 2969 #if defined(FIRST) 2970 struct B10a {}; 2971 struct S10 : B10a {}; 2972 #elif defined(SECOND) 2973 struct B10a {}; 2974 struct S10 : protected B10a {}; 2975 #else 2976 S10 s10; 2977 // expected-error@second.h:* {{'BaseClass::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B10a' with protected access specifier}} 2978 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B10a' with no access specifier}} 2979 #endif 2980 2981 #define DECLS 2982 2983 #if defined(FIRST) || defined(SECOND) 2984 struct Base1 {}; 2985 struct Base2 {}; 2986 struct Base3 {}; 2987 struct Base4 {}; 2988 struct Base5 {}; 2989 #endif 2990 2991 #if defined(FIRST) || defined(SECOND) 2992 struct Valid1 : 2993 Base1, virtual Base2, protected Base3, public Base4, private Base5 { 2994 2995 DECLS 2996 }; 2997 #else 2998 Valid1 v1; 2999 #endif 3000 3001 #if defined(FIRST) || defined(SECOND) 3002 struct Invalid1 : 3003 Base1, virtual Base2, protected Base3, public Base4, private Base5 { 3004 3005 DECLS 3006 ACCESS 3007 }; 3008 #else 3009 Invalid1 i1; 3010 // expected-error@second.h:* {{'BaseClass::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 3011 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 3012 #endif 3013 #undef DECLS 3014 } // namespace BaseClass 3015 3016 namespace PointersAndReferences { 3017 #if defined(FIRST) || defined(SECOND) 3018 template<typename> struct Wrapper{}; 3019 #endif 3020 3021 #if defined(FIRST) 3022 struct S1 { 3023 Wrapper<int*> x; 3024 }; 3025 #elif defined(SECOND) 3026 struct S1 { 3027 Wrapper<float*> x; 3028 }; 3029 #else 3030 S1 s1; 3031 // expected-error@first.h:* {{PointersAndReferences::S1::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S1' in module 'SecondModule'}} 3032 // expected-note@second.h:* {{declaration of 'x' does not match}} 3033 #endif 3034 3035 #if defined(FIRST) 3036 struct S2 { 3037 Wrapper<int &&> x; 3038 }; 3039 #elif defined(SECOND) 3040 struct S2 { 3041 Wrapper<float &&> x; 3042 }; 3043 #else 3044 S2 s2; 3045 // expected-error@first.h:* {{PointersAndReferences::S2::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S2' in module 'SecondModule'}} 3046 // expected-note@second.h:* {{declaration of 'x' does not match}} 3047 #endif 3048 3049 #if defined(FIRST) 3050 struct S3 { 3051 Wrapper<int *> x; 3052 }; 3053 #elif defined(SECOND) 3054 struct S3 { 3055 Wrapper<float *> x; 3056 }; 3057 #else 3058 S3 s3; 3059 // expected-error@first.h:* {{PointersAndReferences::S3::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S3' in module 'SecondModule'}} 3060 // expected-note@second.h:* {{declaration of 'x' does not match}} 3061 #endif 3062 3063 #if defined(FIRST) 3064 struct S4 { 3065 Wrapper<int &> x; 3066 }; 3067 #elif defined(SECOND) 3068 struct S4 { 3069 Wrapper<float &> x; 3070 }; 3071 #else 3072 S4 s4; 3073 // expected-error@first.h:* {{PointersAndReferences::S4::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S4' in module 'SecondModule'}} 3074 // expected-note@second.h:* {{declaration of 'x' does not match}} 3075 #endif 3076 3077 #if defined(FIRST) 3078 struct S5 { 3079 Wrapper<S5 *> x; 3080 }; 3081 #elif defined(SECOND) 3082 struct S5 { 3083 Wrapper<const S5 *> x; 3084 }; 3085 #else 3086 S5 s5; 3087 // expected-error@first.h:* {{'PointersAndReferences::S5::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S5' in module 'SecondModule'}} 3088 // expected-note@second.h:* {{declaration of 'x' does not match}} 3089 #endif 3090 3091 #if defined(FIRST) 3092 struct S6 { 3093 Wrapper<int &> x; 3094 }; 3095 #elif defined(SECOND) 3096 struct S6 { 3097 Wrapper<const int &> x; 3098 }; 3099 #else 3100 S6 s6; 3101 // expected-error@first.h:* {{PointersAndReferences::S6::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S6' in module 'SecondModule'}} 3102 // expected-note@second.h:* {{declaration of 'x' does not match}} 3103 #endif 3104 3105 #define DECLS \ 3106 Wrapper<int *> x1; \ 3107 Wrapper<float *> x2; \ 3108 Wrapper<const float *> x3; \ 3109 Wrapper<int &> x4; \ 3110 Wrapper<int &&> x5; \ 3111 Wrapper<const int &> x6; \ 3112 Wrapper<S1 *> x7; \ 3113 Wrapper<S1 &> x8; \ 3114 Wrapper<S1 &&> x9; 3115 3116 #if defined(FIRST) || defined(SECOND) 3117 struct Valid1 { 3118 DECLS 3119 }; 3120 #else 3121 Valid1 v1; 3122 #endif 3123 3124 #if defined(FIRST) || defined(SECOND) 3125 struct Invalid1 { 3126 DECLS 3127 ACCESS 3128 }; 3129 #else 3130 Invalid1 i1; 3131 // expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 3132 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 3133 #endif 3134 #undef DECLS 3135 } // namespace PointersAndReferences 3136 3137 namespace FunctionTemplate { 3138 #if defined(FIRST) 3139 struct S1 { 3140 template <int, int> void foo(); 3141 }; 3142 #elif defined(SECOND) 3143 struct S1 { 3144 template <int> void foo(); 3145 }; 3146 #else 3147 S1 s1; 3148 // expected-error@first.h:* {{'FunctionTemplate::S1::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S1' in module 'SecondModule'}} 3149 // expected-note@second.h:* {{declaration of 'foo' does not match}} 3150 #endif 3151 3152 #if defined(FIRST) 3153 struct S2 { 3154 template <char> void foo(); 3155 }; 3156 #elif defined(SECOND) 3157 struct S2 { 3158 template <int> void foo(); 3159 }; 3160 #else 3161 S2 s2; 3162 // expected-error@first.h:* {{'FunctionTemplate::S2::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S2' in module 'SecondModule'}} 3163 // expected-note@second.h:* {{declaration of 'foo' does not match}} 3164 #endif 3165 3166 #if defined(FIRST) 3167 struct S3 { 3168 template <int x> void foo(); 3169 }; 3170 #elif defined(SECOND) 3171 struct S3 { 3172 template <int y> void foo(); 3173 }; 3174 #else 3175 S3 s3; 3176 // expected-error@second.h:* {{'FunctionTemplate::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter named 'y'}} 3177 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}} 3178 #endif 3179 3180 #if defined(FIRST) 3181 struct S4 { 3182 template <int x> void foo(); 3183 }; 3184 #elif defined(SECOND) 3185 struct S4 { 3186 template <int x> void bar(); 3187 }; 3188 #else 3189 S4 s4; 3190 // expected-error@first.h:* {{'FunctionTemplate::S4::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S4' in module 'SecondModule'}} 3191 // expected-note@second.h:* {{definition has no member 'foo'}} 3192 #endif 3193 3194 #if defined(FIRST) 3195 struct S5 { 3196 template <int x> void foo(); 3197 }; 3198 #elif defined(SECOND) 3199 struct S5 { 3200 public: 3201 template <int x> void foo(); 3202 }; 3203 #else 3204 S5 s5; 3205 // expected-error@second.h:* {{'FunctionTemplate::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 3206 // expected-note@first.h:* {{but in 'FirstModule' found function template}} 3207 #endif 3208 3209 #if defined(FIRST) 3210 struct S6 { 3211 template <typename x = int> void foo(); 3212 }; 3213 #elif defined(SECOND) 3214 struct S6 { 3215 template <typename x> void foo(); 3216 }; 3217 #else 3218 S6 s6; 3219 // expected-error@second.h:* {{'FunctionTemplate::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no default argument}} 3220 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}} 3221 #endif 3222 3223 #if defined(FIRST) 3224 struct S7 { 3225 template <typename x = void> void foo(); 3226 }; 3227 #elif defined(SECOND) 3228 struct S7 { 3229 template <typename x = int> void foo(); 3230 }; 3231 #else 3232 S7 s7; 3233 // expected-error@second.h:* {{'FunctionTemplate::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 'int'}} 3234 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'void'}} 3235 #endif 3236 3237 #if defined(FIRST) 3238 template <int> 3239 struct U8 {}; 3240 struct S8 { 3241 template <template<int> class x = U8> void foo(); 3242 }; 3243 #elif defined(SECOND) 3244 template <int> 3245 struct T8 {}; 3246 struct S8{ 3247 template <template<int> class x = T8> void foo(); 3248 }; 3249 #else 3250 S8 s8; 3251 // expected-error@second.h:* {{'FunctionTemplate::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 'T8'}} 3252 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'U8'}} 3253 #endif 3254 3255 #if defined(FIRST) 3256 template <int> 3257 struct U9 {}; 3258 struct S9 { S9(); 3259 template <template<int> class x = U9> void foo(); 3260 }; 3261 #elif defined(SECOND) 3262 struct S9 { S9(); 3263 template <template<int> class x> void foo(); 3264 }; 3265 #else 3266 S9 s9; 3267 // expected-error@second.h:* {{'FunctionTemplate::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no default argument}} 3268 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}} 3269 #endif 3270 3271 #if defined(FIRST) 3272 struct S10 { 3273 template <template<int> class x> void foo(); 3274 template <template<typename> class x> void foo(); 3275 }; 3276 #elif defined(SECOND) 3277 struct S10 { 3278 template <template<typename> class x> void foo(); 3279 template <template<int> class x> void foo(); 3280 }; 3281 #else 3282 S10 s10; 3283 // expected-error@second.h:* {{'FunctionTemplate::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with one type}} 3284 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}} 3285 #endif 3286 3287 #if defined(FIRST) 3288 struct S11 { 3289 template <template<int> class x> void foo(); 3290 }; 3291 #elif defined(SECOND) 3292 struct S11 { 3293 template <template<int> class> void foo(); 3294 }; 3295 #else 3296 S11 s11; 3297 // expected-error@second.h:* {{'FunctionTemplate::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no name}} 3298 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}} 3299 #endif 3300 3301 #if defined(FIRST) 3302 struct S12 { 3303 template <class> void foo(); 3304 template <class, class> void foo(); 3305 }; 3306 #elif defined(SECOND) 3307 struct S12 { 3308 template <class, class> void foo(); 3309 template <class> void foo(); 3310 }; 3311 #else 3312 S12 s12; 3313 // expected-error@second.h:* {{'FunctionTemplate::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 2 template parameters}} 3314 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1 template parameter}} 3315 #endif 3316 3317 #if defined(FIRST) 3318 struct S13 { 3319 template <class = int> void foo(); 3320 }; 3321 #elif defined(SECOND) 3322 struct S13 { 3323 template <class = void> void foo(); 3324 }; 3325 #else 3326 S13 s13; 3327 // expected-error@second.h:* {{'FunctionTemplate::S13' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 'void'}} 3328 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'int'}} 3329 #endif 3330 3331 #if defined(FIRST) 3332 struct S14 { 3333 template <class = void> void foo(); 3334 }; 3335 #elif defined(SECOND) 3336 struct S14 { 3337 template <class> void foo(); 3338 }; 3339 #else 3340 S14 s14; 3341 // expected-error@second.h:* {{'FunctionTemplate::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no default argument}} 3342 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}} 3343 #endif 3344 3345 #if defined(FIRST) 3346 struct S15 { 3347 template <class> void foo(); 3348 }; 3349 #elif defined(SECOND) 3350 struct S15 { 3351 template <class = void> void foo(); 3352 }; 3353 #else 3354 S15 s15; 3355 // expected-error@second.h:* {{'FunctionTemplate::S15' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument}} 3356 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}} 3357 #endif 3358 3359 #if defined(FIRST) 3360 struct S16 { 3361 template <short> void foo(); 3362 }; 3363 #elif defined(SECOND) 3364 struct S16 { 3365 template <short = 1> void foo(); 3366 }; 3367 #else 3368 S16 s16; 3369 // expected-error@second.h:* {{'FunctionTemplate::S16' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument}} 3370 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}} 3371 #endif 3372 3373 #if defined(FIRST) 3374 struct S17 { 3375 template <short = 2> void foo(); 3376 }; 3377 #elif defined(SECOND) 3378 struct S17 { 3379 template <short = 1 + 1> void foo(); 3380 }; 3381 #else 3382 S17 s17; 3383 // expected-error@second.h:* {{'FunctionTemplate::S17' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 1 + 1}} 3384 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 2}} 3385 #endif 3386 3387 #if defined(FIRST) 3388 struct S18 { 3389 template <short> void foo(); 3390 template <int> void foo(); 3391 }; 3392 #elif defined(SECOND) 3393 struct S18 { 3394 template <int> void foo(); 3395 template <short> void foo(); 3396 }; 3397 #else 3398 S18 s18; 3399 // expected-error@second.h:* {{'FunctionTemplate::S18' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with one type}} 3400 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}} 3401 #endif 3402 3403 #if defined(FIRST) 3404 struct S19 { 3405 template <short> void foo(); 3406 template <short...> void foo(); 3407 }; 3408 #elif defined(SECOND) 3409 struct S19 { 3410 template <short...> void foo(); 3411 template <short> void foo(); 3412 }; 3413 #else 3414 S19 s19; 3415 // expected-error@second.h:* {{'FunctionTemplate::S19' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a template parameter pack}} 3416 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}} 3417 #endif 3418 3419 #if defined(FIRST) 3420 struct S20 { 3421 template <class> void foo(); 3422 template <class...> void foo(); 3423 }; 3424 #elif defined(SECOND) 3425 struct S20 { 3426 template <class...> void foo(); 3427 template <class> void foo(); 3428 }; 3429 #else 3430 S20 s20; 3431 // expected-error@second.h:* {{'FunctionTemplate::S20' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a template parameter pack}} 3432 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}} 3433 #endif 3434 3435 #if defined(FIRST) 3436 struct S21 { 3437 template <template<class> class...> void foo(); 3438 template <template<class> class> void foo(); 3439 }; 3440 #elif defined(SECOND) 3441 struct S21 { 3442 template <template<class> class> void foo(); 3443 template <template<class> class...> void foo(); 3444 }; 3445 #else 3446 S21 s21; 3447 // expected-error@second.h:* {{'FunctionTemplate::S21' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter not being a template parameter pack}} 3448 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter being a template parameter pack}} 3449 #endif 3450 3451 #if defined(FIRST) 3452 struct S22 { 3453 template <template<class> class> void foo(); 3454 template <class> void foo(); 3455 template <int> void foo(); 3456 }; 3457 #elif defined(SECOND) 3458 struct S22 { 3459 template <class> void foo(); 3460 template <int> void foo(); 3461 template <template<class> class> void foo(); 3462 }; 3463 #else 3464 S22 s22; 3465 // expected-error@second.h:* {{'FunctionTemplate::S22' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a type template parameter}} 3466 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a template template parameter}} 3467 #endif 3468 3469 #if defined(FIRST) 3470 struct S23 { 3471 template <class> void foo(); 3472 template <int> void foo(); 3473 template <template<class> class> void foo(); 3474 }; 3475 #elif defined(SECOND) 3476 struct S23 { 3477 template <int> void foo(); 3478 template <template<class> class> void foo(); 3479 template <class> void foo(); 3480 }; 3481 #else 3482 S23 s23; 3483 // expected-error@second.h:* {{'FunctionTemplate::S23' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a non-type template parameter}} 3484 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a type template parameter}} 3485 #endif 3486 3487 #if defined(FIRST) 3488 struct S24 { 3489 template <int> void foo(); 3490 template <template<class> class> void foo(); 3491 template <class> void foo(); 3492 }; 3493 #elif defined(SECOND) 3494 struct S24 { 3495 template <template<class> class> void foo(); 3496 template <class> void foo(); 3497 template <int> void foo(); 3498 }; 3499 #else 3500 S24 s24; 3501 // expected-error@second.h:* {{'FunctionTemplate::S24' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a template template parameter}} 3502 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a non-type template parameter}} 3503 #endif 3504 3505 #if defined(FIRST) 3506 struct S25 { 3507 template <int> void foo(); 3508 }; 3509 #elif defined(SECOND) 3510 struct S25 { 3511 public: 3512 template <int> void foo(); 3513 }; 3514 #else 3515 S25 s25; 3516 // expected-error@second.h:* {{'FunctionTemplate::S25' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 3517 // expected-note@first.h:* {{but in 'FirstModule' found function template}} 3518 #endif 3519 3520 #define DECLS \ 3521 template <int> \ 3522 void nontype1(); \ 3523 template <int x> \ 3524 void nontype2(); \ 3525 template <int, int> \ 3526 void nontype3(); \ 3527 template <int x = 5> \ 3528 void nontype4(); \ 3529 template <int... x> \ 3530 void nontype5(); \ 3531 \ 3532 template <class> \ 3533 void type1(); \ 3534 template <class x> \ 3535 void type2(); \ 3536 template <class, class> \ 3537 void type3(); \ 3538 template <class x = int> \ 3539 void type4(); \ 3540 template <class... x> \ 3541 void type5(); \ 3542 \ 3543 template <template <int> class> \ 3544 void template1(); \ 3545 template <template <int> class x> \ 3546 void template2(); \ 3547 template <template <int> class, template <int> class> \ 3548 void template3(); \ 3549 template <template <int> class x = U> \ 3550 void template4(); \ 3551 template <template <int> class... x> \ 3552 void template5(); 3553 3554 #if defined(FIRST) || defined(SECOND) 3555 template<int> 3556 struct U {}; 3557 struct Valid1 { 3558 DECLS 3559 }; 3560 #else 3561 Valid1 v1; 3562 #endif 3563 3564 #if defined(FIRST) || defined(SECOND) 3565 struct Invalid1 { 3566 DECLS 3567 ACCESS 3568 }; 3569 #else 3570 Invalid1 i1; 3571 // expected-error@second.h:* {{'FunctionTemplate::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 3572 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 3573 #endif 3574 #undef DECLS 3575 } 3576 3577 namespace Enums { 3578 #if defined(FIRST) 3579 enum E1 { x11 }; 3580 #elif defined(SECOND) 3581 enum E1 {}; 3582 #else 3583 E1 e1; 3584 // expected-error@first.h:* {{'Enums::x11' from module 'FirstModule' is not present in definition of 'Enums::E1' in module 'SecondModule'}} 3585 // expected-note@second.h:* {{definition has no member 'x11'}} 3586 #endif 3587 3588 #if defined(FIRST) 3589 enum E2 {}; 3590 #elif defined(SECOND) 3591 enum E2 { x21 }; 3592 #else 3593 E2 e2; 3594 // expected-error@second.h:* {{'Enums::E2' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 1 element}} 3595 // expected-note@first.h:* {{but in 'FirstModule' found enum with 0 elements}} 3596 #endif 3597 3598 #if defined(FIRST) 3599 enum E3 { x31 }; 3600 #elif defined(SECOND) 3601 enum E3 { x32 }; 3602 #else 3603 E3 e3; 3604 // expected-error@first.h:* {{'Enums::x31' from module 'FirstModule' is not present in definition of 'Enums::E3' in module 'SecondModule'}} 3605 // expected-note@second.h:* {{definition has no member 'x31'}} 3606 #endif 3607 3608 #if defined(FIRST) 3609 enum E4 { x41 }; 3610 #elif defined(SECOND) 3611 enum E4 { x41, x42 }; 3612 #else 3613 E4 e4; 3614 // expected-error@second.h:* {{'Enums::E4' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 2 elements}} 3615 // expected-note@first.h:* {{but in 'FirstModule' found enum with 1 element}} 3616 #endif 3617 3618 #if defined(FIRST) 3619 enum E5 { x51, x52 }; 3620 #elif defined(SECOND) 3621 enum E5 { x51 }; 3622 #else 3623 E5 e5; 3624 // expected-error@first.h:* {{'Enums::x52' from module 'FirstModule' is not present in definition of 'Enums::E5' in module 'SecondModule'}} 3625 // expected-note@second.h:* {{definition has no member 'x52'}} 3626 #endif 3627 3628 #if defined(FIRST) 3629 enum E6 { x61, x62 }; 3630 #elif defined(SECOND) 3631 enum E6 { x62, x61 }; 3632 #else 3633 E6 e6; 3634 // expected-error@second.h:* {{'Enums::E6' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element has name 'x62'}} 3635 // expected-note@first.h:* {{but in 'FirstModule' found 1st element has name 'x61'}} 3636 #endif 3637 3638 #if defined(FIRST) 3639 enum E7 { x71 = 0 }; 3640 #elif defined(SECOND) 3641 enum E7 { x71 }; 3642 #else 3643 E7 e7; 3644 // expected-error@second.h:* {{'Enums::E7' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x71' has an initializer}} 3645 // expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x71' does not have an initializer}} 3646 #endif 3647 3648 #if defined(FIRST) 3649 enum E8 { x81 }; 3650 #elif defined(SECOND) 3651 enum E8 { x81 = 0 }; 3652 #else 3653 E8 e8; 3654 // expected-error@second.h:* {{'Enums::E8' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x81' does not have an initializer}} 3655 // expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x81' has an initializer}} 3656 #endif 3657 3658 #if defined(FIRST) 3659 enum E9 { x91 = 0, x92 = 1 }; 3660 #elif defined(SECOND) 3661 enum E9 { x91 = 0, x92 = 2 - 1 }; 3662 #else 3663 E9 e9; 3664 // expected-error@second.h:* {{'Enums::E9' has different definitions in different modules; definition in module 'SecondModule' first difference is 2nd element 'x92' has an initializer}} 3665 // expected-note@first.h:* {{but in 'FirstModule' found 2nd element 'x92' has different initializer}} 3666 #endif 3667 3668 #if defined(FIRST) 3669 enum class E10 : int {}; 3670 #elif defined(SECOND) 3671 enum class E10 {}; 3672 #else 3673 E10 e10; 3674 // expected-error@second.h:* {{'Enums::E10' has different definitions in different modules; definition in module 'SecondModule' first difference is enum without specified type}} 3675 // expected-note@first.h:* {{but in 'FirstModule' found enum with specified type}} 3676 #endif 3677 3678 #if defined(FIRST) 3679 enum E11 {}; 3680 #elif defined(SECOND) 3681 enum E11 : int {}; 3682 #else 3683 E11 e11; 3684 // expected-error@second.h:* {{'Enums::E11' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type}} 3685 // expected-note@first.h:* {{but in 'FirstModule' found enum without specified type}} 3686 #endif 3687 3688 #if defined(FIRST) 3689 enum struct E12 : long {}; 3690 #elif defined(SECOND) 3691 enum struct E12 : int {}; 3692 #else 3693 E12 e12; 3694 // expected-error@second.h:* {{'Enums::E12' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type 'int'}} 3695 // expected-note@first.h:* {{but in 'FirstModule' found enum with specified type 'long'}} 3696 #endif 3697 3698 #if defined(FIRST) 3699 enum struct E13 {}; 3700 #elif defined(SECOND) 3701 enum E13 {}; 3702 #else 3703 E13 e13; 3704 // expected-error@second.h:* {{'Enums::E13' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is not scoped}} 3705 // expected-note@first.h:* {{but in 'FirstModule' found enum that is scoped}} 3706 #endif 3707 3708 #if defined(FIRST) 3709 enum E14 {}; 3710 #elif defined(SECOND) 3711 enum struct E14 {}; 3712 #else 3713 E14 e14; 3714 // expected-error@second.h:* {{'Enums::E14' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is scoped}} 3715 // expected-note@first.h:* {{but in 'FirstModule' found enum that is not scoped}} 3716 #endif 3717 3718 #if defined(FIRST) 3719 enum class E15 {}; 3720 #elif defined(SECOND) 3721 enum struct E15 {}; 3722 #else 3723 E15 e15; 3724 // expected-error@second.h:* {{'Enums::E15' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword struct}} 3725 // expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword class}} 3726 #endif 3727 3728 #if defined(FIRST) 3729 enum struct E16 {}; 3730 #elif defined(SECOND) 3731 enum class E16 {}; 3732 #else 3733 E16 e16; 3734 // expected-error@second.h:* {{'Enums::E16' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword class}} 3735 // expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword struct}} 3736 #endif 3737 3738 #if defined(FIRST) 3739 enum Valid { v1 = (struct S*)0 == (struct S*)0 }; 3740 #elif defined(SECOND) 3741 struct S {}; 3742 enum Valid { v1 = (struct S*)0 == (struct S*)0 }; 3743 #else 3744 Valid V; 3745 #endif 3746 } // namespace Enums 3747 3748 namespace Types { 3749 namespace Complex { 3750 #if defined(FIRST) 3751 void invalid() { 3752 _Complex float x; 3753 } 3754 void valid() { 3755 _Complex float x; 3756 } 3757 #elif defined(SECOND) 3758 void invalid() { 3759 _Complex double x; 3760 } 3761 void valid() { 3762 _Complex float x; 3763 } 3764 #else 3765 auto function1 = invalid; 3766 // expected-error@second.h:* {{'Types::Complex::invalid' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 3767 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 3768 auto function2 = valid; 3769 #endif 3770 } // namespace Complex 3771 3772 namespace Decltype { 3773 #if defined(FIRST) 3774 void invalid1() { 3775 decltype(1 + 1) x; 3776 } 3777 int global; 3778 void invalid2() { 3779 decltype(global) x; 3780 } 3781 void valid() { 3782 decltype(1.5) x; 3783 decltype(x) y; 3784 } 3785 #elif defined(SECOND) 3786 void invalid1() { 3787 decltype(2) x; 3788 } 3789 float global; 3790 void invalid2() { 3791 decltype(global) x; 3792 } 3793 void valid() { 3794 decltype(1.5) x; 3795 decltype(x) y; 3796 } 3797 #else 3798 auto function1 = invalid1; 3799 // expected-error@second.h:* {{'Types::Decltype::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 3800 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 3801 auto function2 = invalid2; 3802 // FIXME: We should reject the merge of `invalid2` and diagnose about the 3803 // inconsistent definition of `global`. 3804 auto function3 = valid; 3805 #endif 3806 } // namespace Decltype 3807 3808 namespace Auto { 3809 #if defined(FIRST) 3810 void invalid1() { 3811 decltype(auto) x = 1; 3812 } 3813 void invalid2() { 3814 auto x = 1; 3815 } 3816 void invalid3() { 3817 __auto_type x = 1; 3818 } 3819 void valid() { 3820 decltype(auto) x = 1; 3821 auto y = 1; 3822 __auto_type z = 1; 3823 } 3824 #elif defined(SECOND) 3825 void invalid1() { 3826 auto x = 1; 3827 } 3828 void invalid2() { 3829 __auto_type x = 1; 3830 } 3831 void invalid3() { 3832 decltype(auto) x = 1; 3833 } 3834 void valid() { 3835 decltype(auto) x = 1; 3836 auto y = 1; 3837 __auto_type z = 1; 3838 } 3839 #else 3840 auto function1 = invalid1; 3841 // expected-error@second.h:* {{'Types::Auto::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 3842 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 3843 auto function2 = invalid3; 3844 // expected-error@second.h:* {{'Types::Auto::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 3845 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 3846 auto function3 = invalid2; 3847 // expected-error@second.h:* {{'Types::Auto::invalid3' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 3848 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 3849 auto function4 = valid; 3850 #endif 3851 } // namespace Auto 3852 3853 namespace DeducedTemplateSpecialization { 3854 #if defined(FIRST) 3855 template<typename T> struct A {}; 3856 A() -> A<int>; 3857 template<typename T> struct B {}; 3858 B() -> B<int>; 3859 3860 void invalid1() { 3861 A a{}; 3862 } 3863 void invalid2() { 3864 A a{}; 3865 } 3866 void valid() { 3867 B b{}; 3868 } 3869 #elif defined(SECOND) 3870 template<typename T> struct A {}; 3871 A() -> A<float>; 3872 template<typename T> struct B {}; 3873 B() -> B<int>; 3874 3875 void invalid1() { 3876 A a{}; 3877 } 3878 void invalid2() { 3879 B a{}; 3880 } 3881 void valid() { 3882 B b{}; 3883 } 3884 #else 3885 auto function1 = invalid1; 3886 // FIXME: We should reject the merge of `invalid1` due to the inconsistent definition. 3887 auto function2 = invalid2; 3888 // expected-error@second.h:* {{'Types::DeducedTemplateSpecialization::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 3889 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 3890 auto function3 = valid; 3891 #endif 3892 } // namespace DeducedTemplateSpecialization 3893 3894 namespace DependentAddressSpace { 3895 #if defined(FIRST) 3896 template <int A1, int A2> 3897 void invalid1() { 3898 using type = int __attribute__((address_space(A1))); 3899 } 3900 template <int A1> 3901 void invalid2() { 3902 using type = float __attribute__((address_space(A1))); 3903 } 3904 template <int A1, int A2> 3905 void valid() { 3906 using type1 = float __attribute__((address_space(A1))); 3907 using type2 = int __attribute__((address_space(A2))); 3908 using type3 = int __attribute__((address_space(A1 + A2))); 3909 } 3910 #elif defined(SECOND) 3911 template <int A1, int A2> 3912 void invalid1() { 3913 using type = int __attribute__((address_space(A2))); 3914 } 3915 template <int A1> 3916 void invalid2() { 3917 using type = int __attribute__((address_space(A1))); 3918 } 3919 template <int A1, int A2> 3920 void valid() { 3921 using type1 = float __attribute__((address_space(A1))); 3922 using type2 = int __attribute__((address_space(A2))); 3923 using type3 = int __attribute__((address_space(A1 + A2))); 3924 } 3925 #else 3926 template <int A, int B> 3927 class S { 3928 static auto function1 = invalid1<A, B>; 3929 // expected-error@first.h:* {{'Types::DependentAddressSpace::invalid1' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}} 3930 // expected-note@second.h:* {{but in 'SecondModule' found a different body}} 3931 static auto function2 = invalid2<B>; 3932 // expected-error@first.h:* {{'Types::DependentAddressSpace::invalid2' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}} 3933 // expected-note@second.h:* {{but in 'SecondModule' found a different body}} 3934 static auto function3 = valid<A, B>; 3935 }; 3936 #endif 3937 } // namespace DependentAddressSpace 3938 3939 namespace DependentSizedExtVector { 3940 #if defined(FIRST) 3941 template<int Size> 3942 void invalid1() { 3943 typedef int __attribute__((ext_vector_type(Size))) type; 3944 } 3945 template<int Size> 3946 void invalid2() { 3947 typedef int __attribute__((ext_vector_type(Size + 0))) type; 3948 } 3949 template<int Size> 3950 void valid() { 3951 typedef int __attribute__((ext_vector_type(Size))) type; 3952 } 3953 #elif defined(SECOND) 3954 template<int Size> 3955 void invalid1() { 3956 typedef float __attribute__((ext_vector_type(Size))) type; 3957 } 3958 template<int Size> 3959 void invalid2() { 3960 typedef int __attribute__((ext_vector_type(Size + 1))) type; 3961 } 3962 template<int Size> 3963 void valid() { 3964 typedef int __attribute__((ext_vector_type(Size))) type; 3965 } 3966 #else 3967 template <int Num> 3968 class S { 3969 static auto Function1 = invalid1<Num>; 3970 // expected-error@first.h:* {{'Types::DependentSizedExtVector::invalid1' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}} 3971 // expected-note@second.h:* {{but in 'SecondModule' found a different body}} 3972 static auto Function2 = invalid2<Num>; 3973 // expected-error@first.h:* {{'Types::DependentSizedExtVector::invalid2' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}} 3974 // expected-note@second.h:* {{but in 'SecondModule' found a different body}} 3975 static auto Function3 = valid<Num>; 3976 }; 3977 #endif 3978 } // namespace DependentSizedExtVector 3979 3980 namespace InjectedClassName { 3981 #if defined(FIRST) 3982 struct Invalid { 3983 template <int> 3984 struct L2 { 3985 template <int> 3986 struct L3 { 3987 L3 *x; 3988 }; 3989 }; 3990 }; 3991 struct Valid { 3992 template <int> 3993 struct L2 { 3994 template <int> 3995 struct L3 { 3996 L2 *x; 3997 L3 *y; 3998 }; 3999 }; 4000 }; 4001 #elif defined(SECOND) 4002 struct Invalid { 4003 template <int> 4004 struct L2 { 4005 template <int> 4006 struct L3 { 4007 L2 *x; 4008 }; 4009 }; 4010 }; 4011 struct Valid { 4012 template <int> 4013 struct L2 { 4014 template <int> 4015 struct L3 { 4016 L2 *x; 4017 L3 *y; 4018 }; 4019 }; 4020 }; 4021 #else 4022 Invalid::L2<1>::L3<1> invalid; 4023 // expected-error@second.h:* {{'Types::InjectedClassName::Invalid::L2::L3::x' from module 'SecondModule' is not present in definition of 'L3<value-parameter-1-0>' in module 'FirstModule'}} 4024 // expected-note@first.h:* {{declaration of 'x' does not match}} 4025 Valid::L2<1>::L3<1> valid; 4026 #endif 4027 } // namespace InjectedClassName 4028 4029 namespace MemberPointer { 4030 #if defined(FIRST) 4031 struct A {}; 4032 struct B {}; 4033 4034 void Invalid1() { 4035 int A::*x; 4036 }; 4037 void Invalid2() { 4038 int A::*x; 4039 } 4040 void Invalid3() { 4041 int (A::*x)(int); 4042 } 4043 void Valid() { 4044 int A::*x; 4045 float A::*y; 4046 bool B::*z; 4047 void (A::*fun1)(); 4048 int (A::*fun2)(); 4049 void (B::*fun3)(int); 4050 void (B::*fun4)(bool*, int); 4051 } 4052 #elif defined(SECOND) 4053 struct A {}; 4054 struct B {}; 4055 4056 void Invalid1() { 4057 float A::*x; 4058 }; 4059 void Invalid2() { 4060 int B::*x; 4061 } 4062 void Invalid3() { 4063 int (A::*x)(int, int); 4064 } 4065 void Valid() { 4066 int A::*x; 4067 float A::*y; 4068 bool B::*z; 4069 void (A::*fun1)(); 4070 int (A::*fun2)(); 4071 void (B::*fun3)(int); 4072 void (B::*fun4)(bool*, int); 4073 } 4074 #else 4075 auto function1 = Invalid1; 4076 // expected-error@second.h:* {{'Types::MemberPointer::Invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 4077 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 4078 auto function2 = Invalid2; 4079 // expected-error@second.h:* {{'Types::MemberPointer::Invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 4080 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 4081 auto function3 = Invalid3; 4082 // expected-error@second.h:* {{'Types::MemberPointer::Invalid3' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 4083 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 4084 auto function4 = Valid; 4085 #endif 4086 4087 } // namespace MemberPointer 4088 4089 namespace PackExpansion { 4090 #if defined(FIRST) 4091 struct Invalid { 4092 template <class... A> 4093 struct L2 { 4094 template <class... B> 4095 struct L3 { 4096 void run(A...); 4097 void run(B...); 4098 }; 4099 }; 4100 }; 4101 struct Valid { 4102 template <class... A> 4103 struct L2 { 4104 template <class... B> 4105 struct L3 { 4106 void run(A...); 4107 void run(B...); 4108 }; 4109 }; 4110 }; 4111 #elif defined(SECOND) 4112 struct Invalid { 4113 template <class... A> 4114 struct L2 { 4115 template <class... B> 4116 struct L3 { 4117 void run(B...); 4118 void run(A...); 4119 }; 4120 }; 4121 }; 4122 struct Valid { 4123 template <class... A> 4124 struct L2 { 4125 template <class... B> 4126 struct L3 { 4127 void run(A...); 4128 void run(B...); 4129 }; 4130 }; 4131 }; 4132 #else 4133 Invalid::L2<int>::L3<short, bool> invalid; 4134 // expected-error@first.h:* {{'Types::PackExpansion::Invalid::L2::L3' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'run' with 1st parameter of type 'A...'}} 4135 // expected-note@second.h:* {{but in 'SecondModule' found method 'run' with 1st parameter of type 'B...'}} 4136 Valid::L2<int>::L3<short, bool> valid; 4137 #endif 4138 4139 } // namespace PackExpansion 4140 4141 namespace Paren { 4142 #if defined(FIRST) 4143 void invalid() { 4144 int (*x); 4145 } 4146 void valid() { 4147 int (*x); 4148 } 4149 #elif defined(SECOND) 4150 void invalid() { 4151 float (*x); 4152 } 4153 void valid() { 4154 int (*x); 4155 } 4156 #else 4157 auto function1 = invalid; 4158 // expected-error@second.h:* {{'Types::Paren::invalid' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 4159 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 4160 auto function2 = valid; 4161 #endif 4162 } // namespace Paren 4163 4164 namespace SubstTemplateTypeParm { 4165 #if defined(FIRST) 4166 template <class> struct wrapper {}; 4167 template <class, class, class> struct triple {}; 4168 struct Valid { 4169 template <class T, 4170 template <class _T, class _U, class = wrapper<_T>> class A = triple> 4171 struct L2 { 4172 A<T, T> x; 4173 }; 4174 }; 4175 #elif defined(SECOND) 4176 template <class> struct wrapper {}; 4177 template <class, class, class> struct triple {}; 4178 struct Valid { 4179 template <class T, 4180 template <class _T, class _U, class = wrapper<_T>> class A = triple> 4181 struct L2 { 4182 A<T, T> x; 4183 }; 4184 }; 4185 #else 4186 template <class T, 4187 template <class _T, class _U, class = wrapper<_T>> class A = triple> 4188 using V = Valid::L2<T, A>; 4189 #endif 4190 } // namespace SubstTemplateTypeParm 4191 4192 namespace SubstTemplateTypeParmPack { 4193 } // namespace SubstTemplateTypeParmPack 4194 4195 namespace UnaryTransform { 4196 #if defined(FIRST) 4197 enum class E1a : unsigned {}; 4198 struct Invalid1 { 4199 __underlying_type(E1a) x; 4200 }; 4201 enum E2a : unsigned {}; 4202 struct Invalid2 { 4203 __underlying_type(E2a) x; 4204 }; 4205 enum E3a {}; 4206 struct Invalid3 { 4207 __underlying_type(E3a) x; 4208 }; 4209 enum E4a {}; 4210 struct Invalid4 { 4211 __underlying_type(E4a) x; 4212 }; 4213 enum E1 {}; 4214 struct Valid1 { 4215 __underlying_type(E1) x; 4216 }; 4217 enum E2 : unsigned {}; 4218 struct Valid2 { 4219 __underlying_type(E2) x; 4220 }; 4221 enum class E3 {}; 4222 struct Valid3 { 4223 __underlying_type(E3) x; 4224 }; 4225 #elif defined(SECOND) 4226 enum class E1b : signed {}; 4227 struct Invalid1 { 4228 __underlying_type(E1b) x; 4229 }; 4230 enum class E2b : unsigned {}; 4231 struct Invalid2 { 4232 __underlying_type(E2b) x; 4233 }; 4234 enum E3b : int {}; 4235 struct Invalid3 { 4236 __underlying_type(E3b) x; 4237 }; 4238 enum E4b {}; 4239 struct Invalid4 { 4240 __underlying_type(E4b) x; 4241 }; 4242 #else 4243 Invalid1 i1; 4244 // expected-error@first.h:* {{'Types::UnaryTransform::Invalid1::x' from module 'FirstModule' is not present in definition of 'Types::UnaryTransform::Invalid1' in module 'SecondModule'}} 4245 // expected-note@second.h:* {{declaration of 'x' does not match}} 4246 Invalid2 i2; 4247 // expected-error@second.h:* {{'Types::UnaryTransform::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '__underlying_type(E2b)' (aka 'unsigned int')}} 4248 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type '__underlying_type(E2a)' (aka 'unsigned int')}} 4249 Invalid3 i3; 4250 // expected-error@first.h:* {{'Types::UnaryTransform::Invalid3::x' from module 'FirstModule' is not present in definition of 'Types::UnaryTransform::Invalid3' in module 'SecondModule'}} 4251 // expected-note@second.h:* {{declaration of 'x' does not match}} 4252 Invalid4 i4; 4253 // expected-error@second.h:* {{'Types::UnaryTransform::Invalid4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '__underlying_type(E4b)' (aka 'unsigned int')}} 4254 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type '__underlying_type(E4a)' (aka 'unsigned int')}} 4255 Valid1 v1; 4256 Valid2 v2; 4257 Valid3 v3; 4258 #endif 4259 } // namespace UnaryTransform 4260 4261 namespace UnresolvedUsing { 4262 #if defined(FIRST) 4263 template <class T> struct wrapper {}; 4264 template <class T> 4265 struct Invalid { 4266 using typename wrapper<T>::T1; 4267 using typename wrapper<T>::T2; 4268 T1 x; 4269 }; 4270 template <class T> 4271 struct Valid { 4272 using typename wrapper<T>::T1; 4273 using typename wrapper<T>::T2; 4274 T1 x; 4275 T2 y; 4276 }; 4277 #elif defined(SECOND) 4278 template <class T> struct wrapper {}; 4279 template <class T> 4280 struct Invalid { 4281 using typename wrapper<T>::T1; 4282 using typename wrapper<T>::T2; 4283 T2 x; 4284 }; 4285 template <class T> 4286 struct Valid { 4287 using typename wrapper<T>::T1; 4288 using typename wrapper<T>::T2; 4289 T1 x; 4290 T2 y; 4291 }; 4292 #else 4293 template <class T> using I = Invalid<T>; 4294 // expected-error@first.h:* {{'Types::UnresolvedUsing::Invalid::x' from module 'FirstModule' is not present in definition of 'Invalid<T>' in module 'SecondModule'}} 4295 // expected-note@second.h:* {{declaration of 'x' does not match}} 4296 4297 template <class T> using V = Valid<T>; 4298 #endif 4299 4300 } // namespace UnresolvedUsing 4301 4302 // Vector 4303 // void invalid1() { 4304 // __attribute((vector_size(8))) int *x1; 4305 //} 4306 4307 } // namespace Types 4308 4309 // Collection of interesting cases below. 4310 4311 // Naive parsing of AST can lead to cycles in processing. Ensure 4312 // self-references don't trigger an endless cycles of AST node processing. 4313 namespace SelfReference { 4314 #if defined(FIRST) 4315 template <template <int> class T> class Wrapper {}; 4316 4317 template <int N> class S { 4318 S(Wrapper<::SelfReference::S> &Ref) {} 4319 }; 4320 4321 struct Xx { 4322 struct Yy { 4323 }; 4324 }; 4325 4326 Xx::Xx::Xx::Yy yy; 4327 4328 namespace NNS { 4329 template <typename> struct Foo; 4330 template <template <class> class T = NNS::Foo> 4331 struct NestedNamespaceSpecifier {}; 4332 } 4333 #endif 4334 } // namespace SelfReference 4335 4336 namespace FriendFunction { 4337 #if defined(FIRST) 4338 void F(int = 0); 4339 struct S { friend void F(int); }; 4340 #elif defined(SECOND) 4341 void F(int); 4342 struct S { friend void F(int); }; 4343 #else 4344 S s; 4345 #endif 4346 4347 #if defined(FIRST) 4348 void G(int = 0); 4349 struct T { 4350 friend void G(int); 4351 4352 private: 4353 }; 4354 #elif defined(SECOND) 4355 void G(int); 4356 struct T { 4357 friend void G(int); 4358 4359 public: 4360 }; 4361 #else 4362 T t; 4363 // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 4364 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} 4365 #endif 4366 } // namespace FriendFunction 4367 4368 namespace ImplicitDecl { 4369 #if defined(FIRST) 4370 struct S { }; 4371 void S_Constructors() { 4372 // Trigger creation of implicit contructors 4373 S foo; 4374 S bar = foo; 4375 S baz(bar); 4376 } 4377 #elif defined(SECOND) 4378 struct S { }; 4379 #else 4380 S s; 4381 #endif 4382 4383 #if defined(FIRST) 4384 struct T { 4385 private: 4386 }; 4387 void T_Constructors() { 4388 // Trigger creation of implicit contructors 4389 T foo; 4390 T bar = foo; 4391 T baz(bar); 4392 } 4393 #elif defined(SECOND) 4394 struct T { 4395 public: 4396 }; 4397 #else 4398 T t; 4399 // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} 4400 // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}} 4401 #endif 4402 4403 } // namespace ImplicitDecl 4404 4405 namespace TemplatedClass { 4406 #if defined(FIRST) 4407 template <class> 4408 struct S {}; 4409 #elif defined(SECOND) 4410 template <class> 4411 struct S {}; 4412 #else 4413 S<int> s; 4414 #endif 4415 4416 #if defined(FIRST) 4417 template <class> 4418 struct T { 4419 private: 4420 }; 4421 #elif defined(SECOND) 4422 template <class> 4423 struct T { 4424 public: 4425 }; 4426 #else 4427 T<int> t; 4428 // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 4429 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} 4430 #endif 4431 } // namespace TemplatedClass 4432 4433 namespace TemplateClassWithField { 4434 #if defined(FIRST) 4435 template <class A> 4436 struct S { 4437 A a; 4438 }; 4439 #elif defined(SECOND) 4440 template <class A> 4441 struct S { 4442 A a; 4443 }; 4444 #else 4445 S<int> s; 4446 #endif 4447 4448 #if defined(FIRST) 4449 template <class A> 4450 struct T { 4451 A a; 4452 4453 private: 4454 }; 4455 #elif defined(SECOND) 4456 template <class A> 4457 struct T { 4458 A a; 4459 4460 public: 4461 }; 4462 #else 4463 T<int> t; 4464 // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} 4465 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} 4466 #endif 4467 } // namespace TemplateClassWithField 4468 4469 namespace TemplateClassWithTemplateField { 4470 #if defined(FIRST) 4471 template <class A> 4472 class WrapperS; 4473 template <class A> 4474 struct S { 4475 WrapperS<A> a; 4476 }; 4477 #elif defined(SECOND) 4478 template <class A> 4479 class WrapperS; 4480 template <class A> 4481 struct S { 4482 WrapperS<A> a; 4483 }; 4484 #else 4485 template <class A> 4486 class WrapperS{}; 4487 S<int> s; 4488 #endif 4489 4490 #if defined(FIRST) 4491 template <class A> 4492 class WrapperT; 4493 template <class A> 4494 struct T { 4495 WrapperT<A> a; 4496 4497 public: 4498 }; 4499 #elif defined(SECOND) 4500 template <class A> 4501 class WrapperT; 4502 template <class A> 4503 struct T { 4504 WrapperT<A> a; 4505 4506 private: 4507 }; 4508 #else 4509 template <class A> 4510 class WrapperT{}; 4511 T<int> t; 4512 // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 4513 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 4514 #endif 4515 } // namespace TemplateClassWithTemplateField 4516 4517 namespace EnumWithForwardDeclaration { 4518 #if defined(FIRST) 4519 enum E : int; 4520 struct S { 4521 void get(E) {} 4522 }; 4523 #elif defined(SECOND) 4524 enum E : int { A, B }; 4525 struct S { 4526 void get(E) {} 4527 }; 4528 #else 4529 S s; 4530 #endif 4531 4532 #if defined(FIRST) 4533 struct T { 4534 void get(E) {} 4535 public: 4536 }; 4537 #elif defined(SECOND) 4538 struct T { 4539 void get(E) {} 4540 private: 4541 }; 4542 #else 4543 T t; 4544 // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 4545 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 4546 #endif 4547 } // namespace EnumWithForwardDeclaration 4548 4549 namespace StructWithForwardDeclaration { 4550 #if defined(FIRST) 4551 struct P {}; 4552 struct S { 4553 struct P *ptr; 4554 }; 4555 #elif defined(SECOND) 4556 struct S { 4557 struct P *ptr; 4558 }; 4559 #else 4560 S s; 4561 #endif 4562 4563 #if defined(FIRST) 4564 struct Q {}; 4565 struct T { 4566 struct Q *ptr; 4567 public: 4568 }; 4569 #elif defined(SECOND) 4570 struct T { 4571 struct Q *ptr; 4572 private: 4573 }; 4574 #else 4575 T t; 4576 // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 4577 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 4578 #endif 4579 } // namespace StructWithForwardDeclaration 4580 4581 namespace StructWithForwardDeclarationNoDefinition { 4582 #if defined(FIRST) 4583 struct P; 4584 struct S { 4585 struct P *ptr; 4586 }; 4587 #elif defined(SECOND) 4588 struct S { 4589 struct P *ptr; 4590 }; 4591 #else 4592 S s; 4593 #endif 4594 4595 #if defined(FIRST) 4596 struct Q; 4597 struct T { 4598 struct Q *ptr; 4599 4600 public: 4601 }; 4602 #elif defined(SECOND) 4603 struct T { 4604 struct Q *ptr; 4605 4606 private: 4607 }; 4608 #else 4609 T t; 4610 // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} 4611 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} 4612 #endif 4613 } // namespace StructWithForwardDeclarationNoDefinition 4614 4615 namespace LateParsedDefaultArgument { 4616 #if defined(FIRST) 4617 template <typename T> 4618 struct S { 4619 struct R { 4620 void foo(T x = 0) {} 4621 }; 4622 }; 4623 #elif defined(SECOND) 4624 #else 4625 void run() { 4626 S<int>::R().foo(); 4627 } 4628 #endif 4629 } // namespace LateParsedDefaultArgument 4630 4631 namespace LateParsedDefaultArgument { 4632 #if defined(FIRST) 4633 template <typename alpha> struct Bravo { 4634 void charlie(bool delta = false) {} 4635 }; 4636 typedef Bravo<char> echo; 4637 echo foxtrot; 4638 4639 Bravo<char> golf; 4640 #elif defined(SECOND) 4641 #else 4642 #endif 4643 } // LateParsedDefaultArgument 4644 4645 namespace DifferentParameterNameInTemplate { 4646 #if defined(FIRST) || defined(SECOND) 4647 template <typename T> 4648 struct S { 4649 typedef T Type; 4650 4651 static void Run(const Type *name_one); 4652 }; 4653 4654 template <typename T> 4655 void S<T>::Run(const T *name_two) {} 4656 4657 template <typename T> 4658 struct Foo { 4659 ~Foo() { Handler::Run(nullptr); } 4660 Foo() {} 4661 4662 class Handler : public S<T> {}; 4663 4664 void Get(typename Handler::Type *x = nullptr) {} 4665 void Add() { Handler::Run(nullptr); } 4666 }; 4667 #endif 4668 4669 #if defined(FIRST) 4670 struct Beta; 4671 4672 struct Alpha { 4673 Alpha(); 4674 void Go() { betas.Get(); } 4675 Foo<Beta> betas; 4676 }; 4677 4678 #elif defined(SECOND) 4679 struct Beta {}; 4680 4681 struct BetaHelper { 4682 void add_Beta() { betas.Add(); } 4683 Foo<Beta> betas; 4684 }; 4685 4686 #else 4687 Alpha::Alpha() {} 4688 #endif 4689 } // DifferentParameterNameInTemplate 4690 4691 namespace ParameterTest { 4692 #if defined(FIRST) 4693 class X {}; 4694 template <typename G> 4695 class S { 4696 public: 4697 typedef G Type; 4698 static inline G *Foo(const G *a, int * = nullptr); 4699 }; 4700 4701 template<typename G> 4702 G* S<G>::Foo(const G* aaaa, int*) {} 4703 #elif defined(SECOND) 4704 template <typename G> 4705 class S { 4706 public: 4707 typedef G Type; 4708 static inline G *Foo(const G *a, int * = nullptr); 4709 }; 4710 4711 template<typename G> 4712 G* S<G>::Foo(const G* asdf, int*) {} 4713 #else 4714 S<X> s; 4715 // expected-error@first.h:* {{'ParameterTest::S::Foo' has different definitions in different modules; definition in module 'FirstModule' first difference is 1st parameter with name 'aaaa'}} 4716 // expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with name 'asdf'}} 4717 #endif 4718 } // ParameterTest 4719 4720 namespace MultipleTypedefs { 4721 #if defined(FIRST) 4722 typedef int B1; 4723 typedef B1 A1; 4724 struct S1 { 4725 A1 x; 4726 }; 4727 #elif defined(SECOND) 4728 typedef int A1; 4729 struct S1 { 4730 A1 x; 4731 }; 4732 #else 4733 S1 s1; 4734 #endif 4735 4736 #if defined(FIRST) 4737 struct T2 { int x; }; 4738 typedef T2 B2; 4739 typedef B2 A2; 4740 struct S2 { 4741 T2 x; 4742 }; 4743 #elif defined(SECOND) 4744 struct T2 { int x; }; 4745 typedef T2 A2; 4746 struct S2 { 4747 T2 x; 4748 }; 4749 #else 4750 S2 s2; 4751 #endif 4752 4753 #if defined(FIRST) 4754 using A3 = const int; 4755 using B3 = volatile A3; 4756 struct S3 { 4757 B3 x = 1; 4758 }; 4759 #elif defined(SECOND) 4760 using A3 = volatile const int; 4761 using B3 = A3; 4762 struct S3 { 4763 B3 x = 1; 4764 }; 4765 #else 4766 S3 s3; 4767 #endif 4768 4769 #if defined(FIRST) 4770 using A4 = int; 4771 using B4 = A4; 4772 struct S4 { 4773 B4 x; 4774 }; 4775 #elif defined(SECOND) 4776 using A4 = int; 4777 using B4 = ::MultipleTypedefs::A4; 4778 struct S4 { 4779 B4 x; 4780 }; 4781 #else 4782 S4 s4; 4783 #endif 4784 4785 #if defined(FIRST) 4786 using A5 = int; 4787 using B5 = MultipleTypedefs::A5; 4788 struct S5 { 4789 B5 x; 4790 }; 4791 #elif defined(SECOND) 4792 using A5 = int; 4793 using B5 = ::MultipleTypedefs::A5; 4794 struct S5 { 4795 B5 x; 4796 }; 4797 #else 4798 S5 s5; 4799 #endif 4800 } // MultipleTypedefs 4801 4802 namespace DefaultArguments { 4803 #if defined(FIRST) 4804 template <typename T> 4805 struct S { 4806 struct R { 4807 void foo(T x = 0); 4808 }; 4809 }; 4810 #elif defined(SECOND) 4811 template <typename T> 4812 struct S { 4813 struct R { 4814 void foo(T x = 1); 4815 }; 4816 }; 4817 #else 4818 void run() { 4819 S<int>::R().foo(); 4820 } 4821 // expected-error@second.h:* {{'DefaultArguments::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}} 4822 // expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}} 4823 #endif 4824 4825 #if defined(FIRST) 4826 template <typename alpha> struct Bravo { 4827 void charlie(bool delta = false); 4828 }; 4829 typedef Bravo<char> echo; 4830 echo foxtrot; 4831 #elif defined(SECOND) 4832 template <typename alpha> struct Bravo { 4833 void charlie(bool delta = (false)); 4834 }; 4835 typedef Bravo<char> echo; 4836 echo foxtrot; 4837 #else 4838 Bravo<char> golf; 4839 // expected-error@second.h:* {{'DefaultArguments::Bravo' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'charlie' with 1st parameter with a default argument}} 4840 // expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}} 4841 #endif 4842 } // namespace DefaultArguments 4843 4844 namespace FunctionDecl { 4845 #if defined(FIRST) 4846 struct S1 {}; 4847 S1 s1a; 4848 #elif defined(SECOND) 4849 struct S1 {}; 4850 #else 4851 S1 s1; 4852 #endif 4853 4854 #if defined(FIRST) 4855 struct S2 { 4856 S2() = default; 4857 }; 4858 S2 s2a = S2(); 4859 #elif defined(SECOND) 4860 struct S2 { 4861 S2() = default; 4862 }; 4863 #else 4864 S2 s2; 4865 #endif 4866 4867 #if defined(FIRST) 4868 struct S3 { 4869 S3() = delete; 4870 }; 4871 S3* s3c; 4872 #elif defined(SECOND) 4873 struct S3 { 4874 S3() = delete; 4875 }; 4876 #else 4877 S3* s3; 4878 #endif 4879 4880 #if defined(FIRST) || defined(SECOND) 4881 int F1(int x, float y = 2.7) { return 1; } 4882 #else 4883 int I1 = F1(1); 4884 #endif 4885 4886 #if defined(FIRST) 4887 int F2() { return 1; } 4888 #elif defined(SECOND) 4889 double F2() { return 1; } 4890 #else 4891 int I2 = F2(); 4892 // expected-error@-1 {{call to 'F2' is ambiguous}} 4893 // expected-note@first.h:* {{candidate function}} 4894 // expected-note@second.h:* {{candidate function}} 4895 #endif 4896 4897 #if defined(FIRST) 4898 int F3(float) { return 1; } 4899 #elif defined(SECOND) 4900 int F3(double) { return 1; } 4901 #else 4902 int I3 = F3(1); 4903 // expected-error@-1 {{call to 'F3' is ambiguous}} 4904 // expected-note@first.h:* {{candidate function}} 4905 // expected-note@second.h:* {{candidate function}} 4906 #endif 4907 4908 #if defined(FIRST) 4909 int F4(int x) { return 1; } 4910 #elif defined(SECOND) 4911 int F4(int y) { return 1; } 4912 #else 4913 int I4 = F4(1); 4914 // expected-error@second.h:* {{'FunctionDecl::F4' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with name 'y'}} 4915 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with name 'x'}} 4916 #endif 4917 4918 #if defined(FIRST) 4919 int F5(int x) { return 1; } 4920 #elif defined(SECOND) 4921 int F5(int x = 1) { return 1; } 4922 #else 4923 int I5 = F6(1); 4924 // expected-error@second.h:* {{'FunctionDecl::F5' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter without a default argument}} 4925 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a default argument}} 4926 #endif 4927 4928 #if defined(FIRST) 4929 int F6(int x = 2) { return 1; } 4930 #elif defined(SECOND) 4931 int F6(int x = 1) { return 1; } 4932 #else 4933 int I6 = F6(1); 4934 // expected-error@second.h:* {{'FunctionDecl::F6' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with a default argument}} 4935 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a different default argument}} 4936 #endif 4937 4938 using I = int; 4939 #if defined(FIRST) 4940 I F7() { return 0; } 4941 #elif defined(SECOND) 4942 int F7() { return 0; } 4943 #else 4944 int I7 = F7(); 4945 // expected-error@second.h:* {{'FunctionDecl::F7' has different definitions in different modules; definition in module 'SecondModule' first difference is return type is 'int'}} 4946 // expected-note@first.h:* {{but in 'FirstModule' found different return type 'I' (aka 'int')}} 4947 #endif 4948 4949 #if defined(FIRST) 4950 int F8(int) { return 0; } 4951 #elif defined(SECOND) 4952 int F8(I) { return 0; } 4953 #else 4954 int I8 = F8(1); 4955 // expected-error@second.h:* {{'FunctionDecl::F8' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with type 'I' (aka 'int')}} 4956 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int'}} 4957 #endif 4958 4959 #if defined(FIRST) 4960 int F9(int[1]) { return 0; } 4961 #elif defined(SECOND) 4962 int F9(int[2]) { return 0; } 4963 #else 4964 int I9 = F9(nullptr); 4965 // expected-error@second.h:* {{'FunctionDecl::F9' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with type 'int *' decayed from 'int[2]'}} 4966 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int *' decayed from 'int[1]'}} 4967 #endif 4968 4969 #if defined(FIRST) 4970 int F10() { return 1; } 4971 #elif defined(SECOND) 4972 int F10() { return 2; } 4973 #else 4974 int I10 = F10(); 4975 #endif 4976 // expected-error@second.h:* {{'FunctionDecl::F10' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 4977 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 4978 4979 #if defined(FIRST) 4980 struct S11 { 4981 template <int> void foo(); 4982 }; 4983 #elif defined(SECOND) 4984 struct S11 { 4985 template <int> void foo(); 4986 }; 4987 template <int> void S11::foo() {} 4988 #else 4989 S11 s11; 4990 #endif 4991 4992 #if defined(FIRST) 4993 struct S12 { 4994 void foo(int x); 4995 }; 4996 #elif defined(SECOND) 4997 struct S12 { 4998 void foo(int x); 4999 }; 5000 void S12::foo(int y) {} 5001 #else 5002 S12 s12; 5003 #endif 5004 5005 #if defined(FIRST) 5006 struct S13 { 5007 void foo(int x); 5008 }; 5009 void S13::foo(int y) {} 5010 #elif defined(SECOND) 5011 struct S13 { 5012 void foo(int x); 5013 }; 5014 void S13::foo(int y) {} 5015 #else 5016 S13 s13; 5017 #endif 5018 } // namespace FunctionDecl 5019 5020 namespace DeclTemplateArguments { 5021 #if defined(FIRST) 5022 int foo() { return 1; } 5023 int bar() { return foo(); } 5024 #elif defined(SECOND) 5025 template <class T = int> 5026 int foo() { return 2; } 5027 int bar() { return foo<>(); } 5028 #else 5029 int num = bar(); 5030 // expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} 5031 // expected-note@first.h:* {{but in 'FirstModule' found a different body}} 5032 #endif 5033 } 5034 5035 namespace FunctionProtoTypeDecay { 5036 #if defined(FIRST) 5037 struct S1 { 5038 struct X {}; 5039 using Y = X(X()); 5040 }; 5041 #elif defined(SECOND) 5042 struct S1 { 5043 struct X {}; 5044 using Y = X(X(X())); 5045 }; 5046 #else 5047 S1 s1; 5048 // expected-error@first.h:* {{'FunctionProtoTypeDecay::S1::Y' from module 'FirstModule' is not present in definition of 'FunctionProtoTypeDecay::S1' in module 'SecondModule'}} 5049 // expected-note@second.h:* {{declaration of 'Y' does not match}} 5050 #endif 5051 5052 #if defined(FIRST) 5053 struct S2 { 5054 struct X {}; 5055 using Y = 5056 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X( 5057 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X( 5058 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X( 5059 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X( 5060 )))))))))))))))) 5061 )))))))))))))))) 5062 )))))))))))))))) 5063 )))))))))))))))); 5064 }; 5065 #elif defined(SECOND) 5066 #else 5067 S2 s2; 5068 #endif 5069 } 5070 5071 namespace TypedefStruct { 5072 #if defined(FIRST) 5073 struct T1; 5074 class S1 { 5075 T1* t; 5076 }; 5077 #elif defined(SECOND) 5078 typedef struct T1 {} T1; 5079 class S1 { 5080 T1* t; 5081 }; 5082 #else 5083 S1 s1; 5084 #endif 5085 5086 #if defined(FIRST) 5087 struct T2; 5088 class S2 { 5089 const T2* t = nullptr; 5090 }; 5091 #elif defined(SECOND) 5092 typedef struct T2 {} T2; 5093 class S2 { 5094 const T2* t = nullptr; 5095 }; 5096 #else 5097 S2 s2; 5098 #endif 5099 5100 #if defined(FIRST) 5101 struct T3; 5102 class S3 { 5103 T3* const t = nullptr; 5104 }; 5105 #elif defined(SECOND) 5106 typedef struct T3 {} T3; 5107 class S3 { 5108 T3* const t = nullptr; 5109 }; 5110 #else 5111 S3 s3; 5112 #endif 5113 5114 #if defined(FIRST) 5115 namespace NS4 { 5116 struct T4; 5117 } // namespace NS4 5118 class S4 { 5119 NS4::T4* t = 0; 5120 }; 5121 #elif defined(SECOND) 5122 namespace NS4 { 5123 typedef struct T4 {} T4; 5124 } // namespace NS4 5125 class S4 { 5126 NS4::T4* t = 0; 5127 }; 5128 #else 5129 S4 s4; 5130 #endif 5131 5132 #if defined(FIRST) 5133 namespace NS5 { 5134 struct T5; 5135 } // namespace NS5 5136 class S5 { 5137 NS5::T5* t = 0; 5138 }; 5139 #elif defined(SECOND) 5140 namespace NS5 { 5141 typedef struct T5_Other {} T5; 5142 } // namespace NS4 5143 class S5 { 5144 NS5::T5* t = 0; 5145 }; 5146 #else 5147 S5 s5; 5148 // expected-error@first.h:* {{'TypedefStruct::S5::t' from module 'FirstModule' is not present in definition of 'TypedefStruct::S5' in module 'SecondModule'}} 5149 // expected-note@second.h:* {{declaration of 't' does not match}} 5150 #endif 5151 } // namespace TypedefStruct 5152 5153 #if defined (FIRST) 5154 typedef int T; 5155 namespace A { 5156 struct X { T n; }; 5157 } 5158 #elif defined(SECOND) 5159 namespace A { 5160 typedef int T; 5161 struct X { T n; }; 5162 } 5163 #else 5164 A::X x; 5165 #endif 5166 5167 // Keep macros contained to one file. 5168 #ifdef FIRST 5169 #undef FIRST 5170 #endif 5171 5172 #ifdef SECOND 5173 #undef SECOND 5174 #endif 5175 5176 #ifdef ACCESS 5177 #undef ACCESS 5178 #endif 5179