Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1 | // Clear and create directories |
| 2 | // RUN: rm -rf %t |
| 3 | // RUN: mkdir %t |
| 4 | // RUN: mkdir %t/cache |
| 5 | // RUN: mkdir %t/Inputs |
| 6 | |
| 7 | // Build first header file |
| 8 | // RUN: echo "#define FIRST" >> %t/Inputs/first.h |
| 9 | // RUN: cat %s >> %t/Inputs/first.h |
| 10 | |
| 11 | // Build second header file |
| 12 | // RUN: echo "#define SECOND" >> %t/Inputs/second.h |
| 13 | // RUN: cat %s >> %t/Inputs/second.h |
| 14 | |
| 15 | // Build module map file |
| 16 | // RUN: echo "module FirstModule {" >> %t/Inputs/module.map |
| 17 | // RUN: echo " header \"first.h\"" >> %t/Inputs/module.map |
| 18 | // RUN: echo "}" >> %t/Inputs/module.map |
| 19 | // RUN: echo "module SecondModule {" >> %t/Inputs/module.map |
| 20 | // RUN: echo " header \"second.h\"" >> %t/Inputs/module.map |
| 21 | // RUN: echo "}" >> %t/Inputs/module.map |
| 22 | |
| 23 | // Run test |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 24 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 25 | |
| 26 | #if !defined(FIRST) && !defined(SECOND) |
| 27 | #include "first.h" |
| 28 | #include "second.h" |
| 29 | #endif |
| 30 | |
| 31 | namespace AccessSpecifiers { |
| 32 | #if defined(FIRST) |
| 33 | struct S1 { |
| 34 | }; |
| 35 | #elif defined(SECOND) |
| 36 | struct S1 { |
| 37 | private: |
| 38 | }; |
| 39 | #else |
| 40 | S1 s1; |
| 41 | // expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 42 | // expected-note@first.h:* {{but in 'FirstModule' found end of class}} |
| 43 | #endif |
| 44 | |
| 45 | #if defined(FIRST) |
| 46 | struct S2 { |
| 47 | public: |
| 48 | }; |
| 49 | #elif defined(SECOND) |
| 50 | struct S2 { |
| 51 | protected: |
| 52 | }; |
| 53 | #else |
| 54 | S2 s2; |
| 55 | // expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}} |
| 56 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 57 | #endif |
| 58 | } // namespace AccessSpecifiers |
| 59 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 60 | namespace StaticAssert { |
| 61 | #if defined(FIRST) |
| 62 | struct S1 { |
| 63 | static_assert(1 == 1, "First"); |
| 64 | }; |
| 65 | #elif defined(SECOND) |
| 66 | struct S1 { |
| 67 | static_assert(1 == 1, "Second"); |
| 68 | }; |
| 69 | #else |
| 70 | S1 s1; |
| 71 | // expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}} |
| 72 | // expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}} |
| 73 | #endif |
| 74 | |
| 75 | #if defined(FIRST) |
| 76 | struct S2 { |
| 77 | static_assert(2 == 2, "Message"); |
| 78 | }; |
| 79 | #elif defined(SECOND) |
| 80 | struct S2 { |
| 81 | static_assert(2 == 2); |
| 82 | }; |
| 83 | #else |
| 84 | S2 s2; |
| 85 | // expected-error@second.h:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}} |
| 86 | // expected-note@first.h:* {{but in 'FirstModule' found static assert with message}} |
| 87 | #endif |
| 88 | |
| 89 | #if defined(FIRST) |
| 90 | struct S3 { |
| 91 | static_assert(3 == 3, "Message"); |
| 92 | }; |
| 93 | #elif defined(SECOND) |
| 94 | struct S3 { |
| 95 | static_assert(3 != 4, "Message"); |
| 96 | }; |
| 97 | #else |
| 98 | S3 s3; |
| 99 | // expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}} |
| 100 | // expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}} |
| 101 | #endif |
| 102 | |
| 103 | #if defined(FIRST) |
| 104 | struct S4 { |
| 105 | static_assert(4 == 4, "Message"); |
| 106 | }; |
| 107 | #elif defined(SECOND) |
| 108 | struct S4 { |
| 109 | public: |
| 110 | }; |
| 111 | #else |
| 112 | S4 s4; |
| 113 | // expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 114 | // expected-note@first.h:* {{but in 'FirstModule' found static assert}} |
| 115 | #endif |
| 116 | } |
| 117 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 118 | namespace Field { |
| 119 | #if defined(FIRST) |
| 120 | struct S1 { |
| 121 | int x; |
| 122 | private: |
| 123 | int y; |
| 124 | }; |
| 125 | #elif defined(SECOND) |
| 126 | struct S1 { |
| 127 | int x; |
| 128 | int y; |
| 129 | }; |
| 130 | #else |
| 131 | S1 s1; |
| 132 | // expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} |
| 133 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 134 | #endif |
| 135 | |
| 136 | #if defined(FIRST) |
| 137 | struct S2 { |
| 138 | int x; |
| 139 | int y; |
| 140 | }; |
| 141 | #elif defined(SECOND) |
| 142 | struct S2 { |
| 143 | int y; |
| 144 | int x; |
| 145 | }; |
| 146 | #else |
| 147 | S2 s2; |
| 148 | // expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} |
| 149 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}} |
| 150 | #endif |
Richard Trieu | bcaaf96 | 2017-02-23 03:25:57 +0000 | [diff] [blame] | 151 | |
| 152 | #if defined(FIRST) |
| 153 | struct S3 { |
| 154 | double x; |
| 155 | }; |
| 156 | #elif defined(SECOND) |
| 157 | struct S3 { |
| 158 | int x; |
| 159 | }; |
| 160 | #else |
| 161 | S3 s3; |
| 162 | // expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}} |
| 163 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 164 | #endif |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 165 | |
| 166 | #if defined(FIRST) |
| 167 | typedef int A; |
| 168 | struct S4 { |
| 169 | A x; |
| 170 | }; |
| 171 | |
| 172 | struct S5 { |
| 173 | A x; |
| 174 | }; |
| 175 | #elif defined(SECOND) |
| 176 | typedef int B; |
| 177 | struct S4 { |
| 178 | B x; |
| 179 | }; |
| 180 | |
| 181 | struct S5 { |
| 182 | int x; |
| 183 | }; |
| 184 | #else |
| 185 | S4 s4; |
Alex Lorenz | 76377dc | 2017-03-10 15:04:58 +0000 | [diff] [blame] | 186 | // expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'Field::B' (aka 'int')}} |
| 187 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}} |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 188 | |
| 189 | S5 s5; |
| 190 | // expected-error@second.h:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}} |
Alex Lorenz | 76377dc | 2017-03-10 15:04:58 +0000 | [diff] [blame] | 191 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}} |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 192 | #endif |
| 193 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 194 | #if defined(FIRST) |
| 195 | struct S6 { |
| 196 | unsigned x; |
| 197 | }; |
| 198 | #elif defined(SECOND) |
| 199 | struct S6 { |
| 200 | unsigned x : 1; |
| 201 | }; |
| 202 | #else |
| 203 | S6 s6; |
| 204 | // expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}} |
| 205 | // expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}} |
| 206 | #endif |
| 207 | |
| 208 | #if defined(FIRST) |
| 209 | struct S7 { |
| 210 | unsigned x : 2; |
| 211 | }; |
| 212 | #elif defined(SECOND) |
| 213 | struct S7 { |
| 214 | unsigned x : 1; |
| 215 | }; |
| 216 | #else |
| 217 | S7 s7; |
| 218 | // expected-error@second.h:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}} |
| 219 | // expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}} |
| 220 | #endif |
| 221 | |
| 222 | #if defined(FIRST) |
| 223 | struct S8 { |
| 224 | unsigned x : 2; |
| 225 | }; |
| 226 | #elif defined(SECOND) |
| 227 | struct S8 { |
| 228 | unsigned x : 1 + 1; |
| 229 | }; |
| 230 | #else |
| 231 | S8 s8; |
| 232 | // expected-error@second.h:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}} |
| 233 | // expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}} |
| 234 | #endif |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 235 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 236 | #if defined(FIRST) |
| 237 | struct S9 { |
| 238 | mutable int x; |
| 239 | }; |
| 240 | #elif defined(SECOND) |
| 241 | struct S9 { |
| 242 | int x; |
| 243 | }; |
| 244 | #else |
| 245 | S9 s9; |
| 246 | // expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}} |
| 247 | // expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}} |
| 248 | #endif |
| 249 | |
| 250 | #if defined(FIRST) |
| 251 | struct S10 { |
| 252 | unsigned x = 5; |
| 253 | }; |
| 254 | #elif defined(SECOND) |
| 255 | struct S10 { |
| 256 | unsigned x; |
| 257 | }; |
| 258 | #else |
| 259 | S10 s10; |
| 260 | // expected-error@second.h:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initalizer}} |
| 261 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}} |
| 262 | #endif |
| 263 | |
| 264 | #if defined(FIRST) |
| 265 | struct S11 { |
| 266 | unsigned x = 5; |
| 267 | }; |
| 268 | #elif defined(SECOND) |
| 269 | struct S11 { |
| 270 | unsigned x = 7; |
| 271 | }; |
| 272 | #else |
| 273 | S11 s11; |
| 274 | // expected-error@second.h:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}} |
| 275 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}} |
| 276 | #endif |
| 277 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 278 | #if defined(FIRST) |
| 279 | struct S12 { |
| 280 | unsigned x[5]; |
| 281 | }; |
| 282 | #elif defined(SECOND) |
| 283 | struct S12 { |
| 284 | unsigned x[7]; |
| 285 | }; |
| 286 | #else |
| 287 | S12 s12; |
| 288 | // expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}} |
| 289 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 290 | #endif |
| 291 | |
| 292 | #if defined(FIRST) |
| 293 | struct S13 { |
| 294 | unsigned x[7]; |
| 295 | }; |
| 296 | #elif defined(SECOND) |
| 297 | struct S13 { |
| 298 | double x[7]; |
| 299 | }; |
| 300 | #else |
| 301 | S13 s13; |
| 302 | // expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}} |
| 303 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 304 | #endif |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 305 | } // namespace Field |
| 306 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 307 | namespace Method { |
| 308 | #if defined(FIRST) |
| 309 | struct S1 { |
| 310 | void A() {} |
| 311 | }; |
| 312 | #elif defined(SECOND) |
| 313 | struct S1 { |
| 314 | private: |
| 315 | void A() {} |
| 316 | }; |
| 317 | #else |
| 318 | S1 s1; |
| 319 | // expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 320 | // expected-note@first.h:* {{but in 'FirstModule' found method}} |
| 321 | #endif |
| 322 | |
| 323 | #if defined(FIRST) |
| 324 | struct S2 { |
| 325 | void A() {} |
| 326 | void B() {} |
| 327 | }; |
| 328 | #elif defined(SECOND) |
| 329 | struct S2 { |
| 330 | void B() {} |
| 331 | void A() {} |
| 332 | }; |
| 333 | #else |
| 334 | S2 s2; |
| 335 | // expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}} |
| 336 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A'}} |
| 337 | #endif |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 338 | |
| 339 | #if defined(FIRST) |
| 340 | struct S3 { |
| 341 | static void A() {} |
Richard Trieu | f4b54fe | 2017-03-04 03:04:15 +0000 | [diff] [blame] | 342 | void A(int) {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 343 | }; |
| 344 | #elif defined(SECOND) |
| 345 | struct S3 { |
Richard Trieu | f4b54fe | 2017-03-04 03:04:15 +0000 | [diff] [blame] | 346 | void A(int) {} |
| 347 | static void A() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 348 | }; |
| 349 | #else |
| 350 | S3 s3; |
| 351 | // expected-error@second.h:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}} |
| 352 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}} |
| 353 | #endif |
| 354 | |
| 355 | #if defined(FIRST) |
| 356 | struct S4 { |
| 357 | virtual void A() {} |
| 358 | void B() {} |
| 359 | }; |
| 360 | #elif defined(SECOND) |
| 361 | struct S4 { |
| 362 | void A() {} |
| 363 | virtual void B() {} |
| 364 | }; |
| 365 | #else |
| 366 | S4 s4; |
| 367 | // expected-error@second.h:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}} |
| 368 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}} |
| 369 | #endif |
| 370 | |
| 371 | #if defined(FIRST) |
| 372 | struct S5 { |
| 373 | virtual void A() = 0; |
| 374 | virtual void B() {}; |
| 375 | }; |
| 376 | #elif defined(SECOND) |
| 377 | struct S5 { |
| 378 | virtual void A() {} |
| 379 | virtual void B() = 0; |
| 380 | }; |
| 381 | #else |
| 382 | S5 *s5; |
| 383 | // expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}} |
| 384 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}} |
| 385 | #endif |
| 386 | |
| 387 | #if defined(FIRST) |
| 388 | struct S6 { |
| 389 | inline void A() {} |
| 390 | }; |
| 391 | #elif defined(SECOND) |
| 392 | struct S6 { |
| 393 | void A() {} |
| 394 | }; |
| 395 | #else |
| 396 | S6 s6; |
| 397 | // expected-error@second.h:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}} |
| 398 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}} |
| 399 | #endif |
| 400 | |
| 401 | #if defined(FIRST) |
| 402 | struct S7 { |
| 403 | void A() volatile {} |
| 404 | void A() {} |
| 405 | }; |
| 406 | #elif defined(SECOND) |
| 407 | struct S7 { |
| 408 | void A() {} |
| 409 | void A() volatile {} |
| 410 | }; |
| 411 | #else |
| 412 | S7 s7; |
| 413 | // expected-error@second.h:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}} |
| 414 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}} |
| 415 | #endif |
| 416 | |
| 417 | #if defined(FIRST) |
| 418 | struct S8 { |
| 419 | void A() const {} |
| 420 | void A() {} |
| 421 | }; |
| 422 | #elif defined(SECOND) |
| 423 | struct S8 { |
| 424 | void A() {} |
| 425 | void A() const {} |
| 426 | }; |
| 427 | #else |
| 428 | S8 s8; |
| 429 | // expected-error@second.h:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}} |
| 430 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}} |
| 431 | #endif |
| 432 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 433 | #if defined(FIRST) |
| 434 | struct S9 { |
| 435 | void A(int x) {} |
| 436 | void A(int x, int y) {} |
| 437 | }; |
| 438 | #elif defined(SECOND) |
| 439 | struct S9 { |
| 440 | void A(int x, int y) {} |
| 441 | void A(int x) {} |
| 442 | }; |
| 443 | #else |
| 444 | S9 s9; |
| 445 | // expected-error@second.h:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}} |
| 446 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}} |
| 447 | #endif |
| 448 | |
| 449 | #if defined(FIRST) |
| 450 | struct S10 { |
| 451 | void A(int x) {} |
| 452 | void A(float x) {} |
| 453 | }; |
| 454 | #elif defined(SECOND) |
| 455 | struct S10 { |
| 456 | void A(float x) {} |
| 457 | void A(int x) {} |
| 458 | }; |
| 459 | #else |
| 460 | S10 s10; |
| 461 | // expected-error@second.h:* {{'Method::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'float'}} |
| 462 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}} |
| 463 | #endif |
| 464 | |
| 465 | #if defined(FIRST) |
| 466 | struct S11 { |
| 467 | void A(int x) {} |
| 468 | }; |
| 469 | #elif defined(SECOND) |
| 470 | struct S11 { |
| 471 | void A(int y) {} |
| 472 | }; |
| 473 | #else |
| 474 | S11 s11; |
| 475 | // expected-error@second.h:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}} |
| 476 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}} |
| 477 | #endif |
| 478 | |
| 479 | #if defined(FIRST) |
| 480 | struct S12 { |
| 481 | void A(int x) {} |
| 482 | }; |
| 483 | #elif defined(SECOND) |
| 484 | struct S12 { |
| 485 | void A(int x = 1) {} |
| 486 | }; |
| 487 | #else |
| 488 | S12 s12; |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 489 | // 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}} |
| 490 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}} |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 491 | #endif |
| 492 | |
| 493 | #if defined(FIRST) |
| 494 | struct S13 { |
| 495 | void A(int x = 1 + 0) {} |
| 496 | }; |
| 497 | #elif defined(SECOND) |
| 498 | struct S13 { |
| 499 | void A(int x = 1) {} |
| 500 | }; |
| 501 | #else |
| 502 | S13 s13; |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 503 | // 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}} |
| 504 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a different default argument}} |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 505 | #endif |
| 506 | |
| 507 | #if defined(FIRST) |
| 508 | struct S14 { |
| 509 | void A(int x[2]) {} |
| 510 | }; |
| 511 | #elif defined(SECOND) |
| 512 | struct S14 { |
| 513 | void A(int x[3]) {} |
| 514 | }; |
| 515 | #else |
| 516 | S14 s14; |
| 517 | // 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]'}} |
| 518 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}} |
| 519 | #endif |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 520 | } // namespace Method |
| 521 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 522 | // Naive parsing of AST can lead to cycles in processing. Ensure |
| 523 | // self-references don't trigger an endless cycles of AST node processing. |
| 524 | namespace SelfReference { |
| 525 | #if defined(FIRST) |
| 526 | template <template <int> class T> class Wrapper {}; |
| 527 | |
| 528 | template <int N> class S { |
| 529 | S(Wrapper<::SelfReference::S> &Ref) {} |
| 530 | }; |
| 531 | |
| 532 | struct Xx { |
| 533 | struct Yy { |
| 534 | }; |
| 535 | }; |
| 536 | |
| 537 | Xx::Xx::Xx::Yy yy; |
| 538 | |
| 539 | namespace NNS { |
| 540 | template <typename> struct Foo; |
| 541 | template <template <class> class T = NNS::Foo> |
| 542 | struct NestedNamespaceSpecifier {}; |
| 543 | } |
| 544 | #endif |
| 545 | } // namespace SelfReference |
| 546 | |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 547 | namespace TypeDef { |
| 548 | #if defined(FIRST) |
| 549 | struct S1 { |
| 550 | typedef int a; |
| 551 | }; |
| 552 | #elif defined(SECOND) |
| 553 | struct S1 { |
| 554 | typedef double a; |
| 555 | }; |
| 556 | #else |
| 557 | S1 s1; |
| 558 | // expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}} |
| 559 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 560 | #endif |
| 561 | |
| 562 | #if defined(FIRST) |
| 563 | struct S2 { |
| 564 | typedef int a; |
| 565 | }; |
| 566 | #elif defined(SECOND) |
| 567 | struct S2 { |
| 568 | typedef int b; |
| 569 | }; |
| 570 | #else |
| 571 | S2 s2; |
| 572 | // expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}} |
| 573 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 574 | #endif |
| 575 | |
| 576 | #if defined(FIRST) |
| 577 | typedef int T; |
| 578 | struct S3 { |
| 579 | typedef T a; |
| 580 | }; |
| 581 | #elif defined(SECOND) |
| 582 | typedef double T; |
| 583 | struct S3 { |
| 584 | typedef T a; |
| 585 | }; |
| 586 | #else |
| 587 | S3 s3; |
| 588 | // expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}} |
| 589 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 590 | #endif |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 591 | |
| 592 | #if defined(FIRST) |
| 593 | struct S4 { |
| 594 | typedef int a; |
| 595 | typedef int b; |
| 596 | }; |
| 597 | #elif defined(SECOND) |
| 598 | struct S4 { |
| 599 | typedef int b; |
| 600 | typedef int a; |
| 601 | }; |
| 602 | #else |
| 603 | S4 s4; |
| 604 | // expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}} |
| 605 | // expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}} |
| 606 | #endif |
| 607 | |
| 608 | #if defined(FIRST) |
| 609 | struct S5 { |
| 610 | typedef int a; |
| 611 | typedef int b; |
| 612 | int x; |
| 613 | }; |
| 614 | #elif defined(SECOND) |
| 615 | struct S5 { |
| 616 | int x; |
| 617 | typedef int b; |
| 618 | typedef int a; |
| 619 | }; |
| 620 | #else |
| 621 | S5 s5; |
| 622 | // expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} |
| 623 | // expected-note@first.h:* {{but in 'FirstModule' found typedef}} |
| 624 | #endif |
| 625 | |
| 626 | #if defined(FIRST) |
| 627 | typedef float F; |
| 628 | struct S6 { |
| 629 | typedef int a; |
| 630 | typedef F b; |
| 631 | }; |
| 632 | #elif defined(SECOND) |
| 633 | struct S6 { |
| 634 | typedef int a; |
| 635 | typedef float b; |
| 636 | }; |
| 637 | #else |
| 638 | S6 s6; |
| 639 | // 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'}} |
| 640 | // expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}} |
| 641 | #endif |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 642 | } // namespace TypeDef |
| 643 | |
| 644 | namespace Using { |
| 645 | #if defined(FIRST) |
| 646 | struct S1 { |
| 647 | using a = int; |
| 648 | }; |
| 649 | #elif defined(SECOND) |
| 650 | struct S1 { |
| 651 | using a = double; |
| 652 | }; |
| 653 | #else |
| 654 | S1 s1; |
| 655 | // expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}} |
| 656 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 657 | #endif |
| 658 | |
| 659 | #if defined(FIRST) |
| 660 | struct S2 { |
| 661 | using a = int; |
| 662 | }; |
| 663 | #elif defined(SECOND) |
| 664 | struct S2 { |
| 665 | using b = int; |
| 666 | }; |
| 667 | #else |
| 668 | S2 s2; |
| 669 | // expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}} |
| 670 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 671 | #endif |
| 672 | |
| 673 | #if defined(FIRST) |
| 674 | typedef int T; |
| 675 | struct S3 { |
| 676 | using a = T; |
| 677 | }; |
| 678 | #elif defined(SECOND) |
| 679 | typedef double T; |
| 680 | struct S3 { |
| 681 | using a = T; |
| 682 | }; |
| 683 | #else |
| 684 | S3 s3; |
| 685 | // expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}} |
| 686 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 687 | #endif |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 688 | |
| 689 | #if defined(FIRST) |
| 690 | struct S4 { |
| 691 | using a = int; |
| 692 | using b = int; |
| 693 | }; |
| 694 | #elif defined(SECOND) |
| 695 | struct S4 { |
| 696 | using b = int; |
| 697 | using a = int; |
| 698 | }; |
| 699 | #else |
| 700 | S4 s4; |
| 701 | // expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}} |
| 702 | // expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}} |
| 703 | #endif |
| 704 | |
| 705 | #if defined(FIRST) |
| 706 | struct S5 { |
| 707 | using a = int; |
| 708 | using b = int; |
| 709 | int x; |
| 710 | }; |
| 711 | #elif defined(SECOND) |
| 712 | struct S5 { |
| 713 | int x; |
| 714 | using b = int; |
| 715 | using a = int; |
| 716 | }; |
| 717 | #else |
| 718 | S5 s5; |
| 719 | // expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} |
| 720 | // expected-note@first.h:* {{but in 'FirstModule' found type alias}} |
| 721 | #endif |
| 722 | |
| 723 | #if defined(FIRST) |
| 724 | typedef float F; |
| 725 | struct S6 { |
| 726 | using a = int; |
| 727 | using b = F; |
| 728 | }; |
| 729 | #elif defined(SECOND) |
| 730 | struct S6 { |
| 731 | using a = int; |
| 732 | using b = float; |
| 733 | }; |
| 734 | #else |
| 735 | S6 s6; |
| 736 | // 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'}} |
| 737 | // expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}} |
| 738 | #endif |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 739 | } // namespace Using |
| 740 | |
Richard Trieu | 58bb7bd | 2017-05-17 02:29:02 +0000 | [diff] [blame] | 741 | namespace RecordType { |
| 742 | #if defined(FIRST) |
| 743 | struct B1 {}; |
| 744 | struct S1 { |
| 745 | B1 x; |
| 746 | }; |
| 747 | #elif defined(SECOND) |
| 748 | struct A1 {}; |
| 749 | struct S1 { |
| 750 | A1 x; |
| 751 | }; |
| 752 | #else |
| 753 | S1 s1; |
| 754 | // expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}} |
| 755 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 756 | #endif |
| 757 | } |
| 758 | |
| 759 | namespace DependentType { |
| 760 | #if defined(FIRST) |
| 761 | template <class T> |
| 762 | class S1 { |
| 763 | typename T::typeA x; |
| 764 | }; |
| 765 | #elif defined(SECOND) |
| 766 | template <class T> |
| 767 | class S1 { |
| 768 | typename T::typeB x; |
| 769 | }; |
| 770 | #else |
| 771 | template<class T> |
| 772 | using U1 = S1<T>; |
| 773 | // expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}} |
| 774 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 775 | #endif |
| 776 | } |
| 777 | |
| 778 | namespace ElaboratedType { |
| 779 | #if defined(FIRST) |
| 780 | namespace N1 { using type = double; } |
| 781 | struct S1 { |
| 782 | N1::type x; |
| 783 | }; |
| 784 | #elif defined(SECOND) |
| 785 | namespace N1 { using type = int; } |
| 786 | struct S1 { |
| 787 | N1::type x; |
| 788 | }; |
| 789 | #else |
| 790 | S1 s1; |
| 791 | // expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}} |
| 792 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 793 | #endif |
| 794 | } |
| 795 | |
| 796 | namespace Enum { |
| 797 | #if defined(FIRST) |
| 798 | enum A1 {}; |
| 799 | struct S1 { |
| 800 | A1 x; |
| 801 | }; |
| 802 | #elif defined(SECOND) |
| 803 | enum A2 {}; |
| 804 | struct S1 { |
| 805 | A2 x; |
| 806 | }; |
| 807 | #else |
| 808 | S1 s1; |
| 809 | // expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}} |
| 810 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 811 | #endif |
| 812 | } |
Hans Wennborg | 2270776 | 2017-04-12 16:40:26 +0000 | [diff] [blame] | 813 | |
Richard Trieu | ce81b19 | 2017-05-17 03:23:35 +0000 | [diff] [blame] | 814 | namespace NestedNamespaceSpecifier { |
| 815 | #if defined(FIRST) |
| 816 | namespace LevelA1 { |
| 817 | using Type = int; |
| 818 | } |
| 819 | |
| 820 | struct S1 { |
| 821 | LevelA1::Type x; |
| 822 | }; |
| 823 | # elif defined(SECOND) |
| 824 | namespace LevelB1 { |
| 825 | namespace LevelC1 { |
| 826 | using Type = int; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | struct S1 { |
| 831 | LevelB1::LevelC1::Type x; |
| 832 | }; |
| 833 | #else |
| 834 | S1 s1; |
| 835 | // 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')}} |
| 836 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}} |
| 837 | #endif |
| 838 | |
| 839 | #if defined(FIRST) |
| 840 | namespace LevelA2 { using Type = int; } |
| 841 | struct S2 { |
| 842 | LevelA2::Type x; |
| 843 | }; |
| 844 | # elif defined(SECOND) |
| 845 | struct S2 { |
| 846 | int x; |
| 847 | }; |
| 848 | #else |
| 849 | S2 s2; |
| 850 | // 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'}} |
| 851 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}} |
| 852 | #endif |
| 853 | |
| 854 | namespace LevelA3 { using Type = int; } |
| 855 | namespace LevelB3 { using Type = int; } |
| 856 | #if defined(FIRST) |
| 857 | struct S3 { |
| 858 | LevelA3::Type x; |
| 859 | }; |
| 860 | # elif defined(SECOND) |
| 861 | struct S3 { |
| 862 | LevelB3::Type x; |
| 863 | }; |
| 864 | #else |
| 865 | S3 s3; |
| 866 | // 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')}} |
| 867 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}} |
| 868 | #endif |
| 869 | |
| 870 | #if defined(FIRST) |
| 871 | struct TA4 { using Type = int; }; |
| 872 | struct S4 { |
| 873 | TA4::Type x; |
| 874 | }; |
| 875 | # elif defined(SECOND) |
| 876 | struct TB4 { using Type = int; }; |
| 877 | struct S4 { |
| 878 | TB4::Type x; |
| 879 | }; |
| 880 | #else |
| 881 | S4 s4; |
| 882 | // 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')}} |
| 883 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}} |
| 884 | #endif |
| 885 | |
| 886 | #if defined(FIRST) |
| 887 | struct T5 { using Type = int; }; |
| 888 | struct S5 { |
| 889 | T5::Type x; |
| 890 | }; |
| 891 | # elif defined(SECOND) |
| 892 | namespace T5 { using Type = int; }; |
| 893 | struct S5 { |
| 894 | T5::Type x; |
| 895 | }; |
| 896 | #else |
| 897 | S5 s5; |
| 898 | // 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')}} |
| 899 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}} |
| 900 | #endif |
| 901 | |
| 902 | #if defined(FIRST) |
| 903 | namespace N6 {using I = int;} |
| 904 | struct S6 { |
| 905 | NestedNamespaceSpecifier::N6::I x; |
| 906 | }; |
| 907 | # elif defined(SECOND) |
| 908 | using I = int; |
| 909 | struct S6 { |
| 910 | ::NestedNamespaceSpecifier::I x; |
| 911 | }; |
| 912 | #else |
| 913 | S6 s6; |
| 914 | // 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')}} |
| 915 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}} |
| 916 | #endif |
| 917 | |
| 918 | #if defined(FIRST) |
| 919 | template <class T, class U> |
| 920 | class S7 { |
| 921 | typename T::type *x = {}; |
| 922 | int z = x->T::foo(); |
| 923 | }; |
| 924 | #elif defined(SECOND) |
| 925 | template <class T, class U> |
| 926 | class S7 { |
| 927 | typename T::type *x = {}; |
| 928 | int z = x->U::foo(); |
| 929 | }; |
| 930 | #else |
| 931 | template <class T, class U> |
| 932 | using U7 = S7<T, U>; |
| 933 | // 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}} |
| 934 | // expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}} |
| 935 | #endif |
| 936 | |
| 937 | #if defined(FIRST) |
| 938 | template <class T> |
| 939 | class S8 { |
| 940 | int x = T::template X<int>::value; |
| 941 | }; |
| 942 | #elif defined(SECOND) |
| 943 | template <class T> |
| 944 | class S8 { |
| 945 | int x = T::template Y<int>::value; |
| 946 | }; |
| 947 | #else |
| 948 | template <class T> |
| 949 | using U8 = S8<T>; |
| 950 | // 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}} |
| 951 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}} |
| 952 | #endif |
| 953 | |
| 954 | #if defined(FIRST) |
| 955 | namespace N9 { using I = int; } |
| 956 | namespace O9 = N9; |
| 957 | struct S9 { |
| 958 | O9::I x; |
| 959 | }; |
| 960 | #elif defined(SECOND) |
| 961 | namespace N9 { using I = int; } |
| 962 | namespace P9 = N9; |
| 963 | struct S9 { |
| 964 | P9::I x; |
| 965 | }; |
| 966 | #else |
| 967 | S9 s9; |
| 968 | // 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')}} |
| 969 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}} |
| 970 | #endif |
| 971 | } |
| 972 | |
Richard Trieu | 96b4962 | 2017-05-31 00:31:58 +0000 | [diff] [blame] | 973 | namespace TemplateSpecializationType { |
| 974 | #if defined(FIRST) |
| 975 | template <class T1> struct U1 {}; |
| 976 | struct S1 { |
| 977 | U1<int> u; |
| 978 | }; |
| 979 | #elif defined(SECOND) |
| 980 | template <class T1, class T2> struct U1 {}; |
| 981 | struct S1 { |
| 982 | U1<int, int> u; |
| 983 | }; |
| 984 | #else |
| 985 | S1 s1; |
| 986 | // expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}} |
| 987 | // expected-note@second.h:* {{declaration of 'u' does not match}} |
| 988 | #endif |
| 989 | |
| 990 | #if defined(FIRST) |
| 991 | template <class T1> struct U2 {}; |
| 992 | struct S2 { |
| 993 | U2<int> u; |
| 994 | }; |
| 995 | #elif defined(SECOND) |
| 996 | template <class T1> struct V1 {}; |
| 997 | struct S2 { |
| 998 | V1<int> u; |
| 999 | }; |
| 1000 | #else |
| 1001 | S2 s2; |
| 1002 | // expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}} |
| 1003 | // expected-note@second.h:* {{declaration of 'u' does not match}} |
| 1004 | #endif |
| 1005 | } |
| 1006 | |
Richard Trieu | 3b261bb7 | 2017-06-13 22:21:18 +0000 | [diff] [blame] | 1007 | namespace TemplateArgument { |
| 1008 | #if defined(FIRST) |
| 1009 | template <class> struct U1{}; |
| 1010 | struct S1 { |
| 1011 | U1<int> x; |
| 1012 | }; |
| 1013 | #elif defined(SECOND) |
| 1014 | template <int> struct U1{}; |
| 1015 | struct S1 { |
| 1016 | U1<1> x; |
| 1017 | }; |
| 1018 | #else |
| 1019 | S1 s1; |
| 1020 | // expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}} |
| 1021 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1022 | #endif |
Richard Trieu | 1dcb405 | 2017-06-14 01:28:00 +0000 | [diff] [blame] | 1023 | |
| 1024 | #if defined(FIRST) |
| 1025 | template <int> struct U2{}; |
| 1026 | struct S2 { |
| 1027 | using T = U2<2>; |
| 1028 | }; |
| 1029 | #elif defined(SECOND) |
| 1030 | template <int> struct U2{}; |
| 1031 | struct S2 { |
| 1032 | using T = U2<(2)>; |
| 1033 | }; |
| 1034 | #else |
| 1035 | S2 s2; |
| 1036 | // 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)>'}} |
| 1037 | // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}} |
| 1038 | #endif |
| 1039 | |
| 1040 | #if defined(FIRST) |
| 1041 | template <int> struct U3{}; |
| 1042 | struct S3 { |
| 1043 | using T = U3<2>; |
| 1044 | }; |
| 1045 | #elif defined(SECOND) |
| 1046 | template <int> struct U3{}; |
| 1047 | struct S3 { |
| 1048 | using T = U3<1 + 1>; |
| 1049 | }; |
| 1050 | #else |
| 1051 | S3 s3; |
| 1052 | // 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>'}} |
| 1053 | // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}} |
| 1054 | #endif |
| 1055 | |
Richard Trieu | ee132d6 | 2017-06-14 03:17:26 +0000 | [diff] [blame] | 1056 | #if defined(FIRST) |
| 1057 | template<class> struct T4a {}; |
| 1058 | template <template <class> class T> struct U4 {}; |
| 1059 | struct S4 { |
| 1060 | U4<T4a> x; |
| 1061 | }; |
| 1062 | #elif defined(SECOND) |
| 1063 | template<class> struct T4b {}; |
| 1064 | template <template <class> class T> struct U4 {}; |
| 1065 | struct S4 { |
| 1066 | U4<T4b> x; |
| 1067 | }; |
| 1068 | #else |
| 1069 | S4 s4; |
| 1070 | // expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}} |
| 1071 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1072 | #endif |
Richard Trieu | 8844c52 | 2017-06-30 22:40:33 +0000 | [diff] [blame^] | 1073 | |
| 1074 | #if defined(FIRST) |
| 1075 | template <class T> struct U5 {}; |
| 1076 | struct S5 { |
| 1077 | U5<int> x; |
| 1078 | }; |
| 1079 | #elif defined(SECOND) |
| 1080 | template <class T> struct U5 {}; |
| 1081 | struct S5 { |
| 1082 | U5<short> x; |
| 1083 | }; |
| 1084 | #else |
| 1085 | S5 s5; |
| 1086 | // expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}} |
| 1087 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1088 | #endif |
| 1089 | |
| 1090 | #if defined(FIRST) |
| 1091 | template <class T> struct U6 {}; |
| 1092 | struct S6 { |
| 1093 | U6<int> x; |
| 1094 | U6<short> y; |
| 1095 | }; |
| 1096 | #elif defined(SECOND) |
| 1097 | template <class T> struct U6 {}; |
| 1098 | struct S6 { |
| 1099 | U6<short> y; |
| 1100 | U6<int> x; |
| 1101 | }; |
| 1102 | #else |
| 1103 | S6 s6; |
| 1104 | // expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}} |
| 1105 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}} |
| 1106 | #endif |
Richard Trieu | d9201d0 | 2017-06-15 01:35:06 +0000 | [diff] [blame] | 1107 | } |
Richard Trieu | ee132d6 | 2017-06-14 03:17:26 +0000 | [diff] [blame] | 1108 | |
Richard Trieu | d9201d0 | 2017-06-15 01:35:06 +0000 | [diff] [blame] | 1109 | namespace TemplateTypeParmType { |
| 1110 | #if defined(FIRST) |
| 1111 | template <class T1, class T2> |
| 1112 | struct S1 { |
| 1113 | T1 x; |
| 1114 | }; |
| 1115 | #elif defined(SECOND) |
| 1116 | template <class T1, class T2> |
| 1117 | struct S1 { |
| 1118 | T2 x; |
| 1119 | }; |
| 1120 | #else |
| 1121 | using TemplateTypeParmType::S1; |
| 1122 | // expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}} |
| 1123 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1124 | #endif |
| 1125 | |
| 1126 | #if defined(FIRST) |
| 1127 | template <int ...Ts> |
| 1128 | struct U2 {}; |
| 1129 | template <int T, int U> |
| 1130 | class S2 { |
| 1131 | typedef U2<U, T> type; |
| 1132 | type x; |
| 1133 | }; |
| 1134 | #elif defined(SECOND) |
| 1135 | template <int ...Ts> |
| 1136 | struct U2 {}; |
| 1137 | template <int T, int U> |
| 1138 | class S2 { |
| 1139 | typedef U2<T, U> type; |
| 1140 | type x; |
| 1141 | }; |
| 1142 | #else |
| 1143 | using TemplateTypeParmType::S2; |
| 1144 | // expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}} |
| 1145 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1146 | // expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}} |
| 1147 | // expected-note@second.h:* {{declaration of 'type' does not match}} |
| 1148 | #endif |
Richard Trieu | 3b261bb7 | 2017-06-13 22:21:18 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 1151 | namespace VarDecl { |
| 1152 | #if defined(FIRST) |
| 1153 | struct S1 { |
| 1154 | static int x; |
| 1155 | static int y; |
| 1156 | }; |
| 1157 | #elif defined(SECOND) |
| 1158 | struct S1 { |
| 1159 | static int y; |
| 1160 | static int x; |
| 1161 | }; |
| 1162 | #else |
| 1163 | S1 s1; |
| 1164 | // 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'}} |
| 1165 | // expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}} |
| 1166 | #endif |
| 1167 | |
| 1168 | #if defined(FIRST) |
| 1169 | struct S2 { |
| 1170 | static int x; |
| 1171 | }; |
| 1172 | #elif defined(SECOND) |
| 1173 | using I = int; |
| 1174 | struct S2 { |
| 1175 | static I x; |
| 1176 | }; |
| 1177 | #else |
| 1178 | S2 s2; |
| 1179 | // 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 'VarDecl::I' (aka 'int')}} |
| 1180 | // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}} |
| 1181 | #endif |
| 1182 | |
| 1183 | #if defined(FIRST) |
| 1184 | struct S3 { |
| 1185 | static const int x = 1; |
| 1186 | }; |
| 1187 | #elif defined(SECOND) |
| 1188 | struct S3 { |
| 1189 | static const int x; |
| 1190 | }; |
| 1191 | #else |
| 1192 | S3 s3; |
| 1193 | // 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}} |
| 1194 | // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}} |
| 1195 | #endif |
| 1196 | |
| 1197 | #if defined(FIRST) |
| 1198 | struct S4 { |
| 1199 | static const int x = 1; |
| 1200 | }; |
| 1201 | #elif defined(SECOND) |
| 1202 | struct S4 { |
| 1203 | static const int x = 2; |
| 1204 | }; |
| 1205 | #else |
| 1206 | S4 s4; |
| 1207 | // 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}} |
| 1208 | // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}} |
| 1209 | #endif |
| 1210 | |
| 1211 | #if defined(FIRST) |
| 1212 | struct S5 { |
| 1213 | static const int x = 1; |
| 1214 | }; |
| 1215 | #elif defined(SECOND) |
| 1216 | struct S5 { |
| 1217 | static constexpr int x = 1; |
| 1218 | }; |
| 1219 | #else |
| 1220 | S5 s5; |
| 1221 | // 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}} |
| 1222 | // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}} |
| 1223 | #endif |
| 1224 | |
| 1225 | #if defined(FIRST) |
| 1226 | struct S6 { |
| 1227 | static const int x = 1; |
| 1228 | }; |
| 1229 | #elif defined(SECOND) |
| 1230 | struct S6 { |
| 1231 | static const int y = 1; |
| 1232 | }; |
| 1233 | #else |
| 1234 | S6 s6; |
| 1235 | // expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}} |
| 1236 | // expected-note@second.h:* {{definition has no member 'x'}} |
| 1237 | #endif |
| 1238 | |
| 1239 | #if defined(FIRST) |
| 1240 | struct S7 { |
| 1241 | static const int x = 1; |
| 1242 | }; |
| 1243 | #elif defined(SECOND) |
| 1244 | struct S7 { |
| 1245 | static const unsigned x = 1; |
| 1246 | }; |
| 1247 | #else |
| 1248 | S7 s7; |
| 1249 | // expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}} |
| 1250 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1251 | #endif |
| 1252 | |
| 1253 | #if defined(FIRST) |
| 1254 | struct S8 { |
| 1255 | public: |
| 1256 | static const int x = 1; |
| 1257 | }; |
| 1258 | #elif defined(SECOND) |
| 1259 | struct S8 { |
| 1260 | static const int x = 1; |
| 1261 | public: |
| 1262 | }; |
| 1263 | #else |
| 1264 | S8 s8; |
| 1265 | // expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}} |
| 1266 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1267 | #endif |
| 1268 | |
| 1269 | #if defined(FIRST) |
| 1270 | struct S9 { |
| 1271 | static const int x = 1; |
| 1272 | }; |
| 1273 | #elif defined(SECOND) |
| 1274 | struct S9 { |
| 1275 | static int x; |
| 1276 | }; |
| 1277 | #else |
| 1278 | S9 s9; |
| 1279 | // expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}} |
| 1280 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1281 | #endif |
| 1282 | |
| 1283 | #if defined(FIRST) |
| 1284 | template <typename T> |
| 1285 | struct S { |
| 1286 | struct R { |
| 1287 | void foo(T x = 0) {} |
| 1288 | }; |
| 1289 | }; |
| 1290 | #elif defined(SECOND) |
| 1291 | template <typename T> |
| 1292 | struct S { |
| 1293 | struct R { |
| 1294 | void foo(T x = 1) {} |
| 1295 | }; |
| 1296 | }; |
| 1297 | #else |
| 1298 | void run() { |
| 1299 | S<int>::R().foo(); |
| 1300 | } |
| 1301 | // expected-error@second.h:* {{'VarDecl::S::R' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo' with 1st parameter with a default argument}} |
| 1302 | // expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}} |
| 1303 | #endif |
| 1304 | |
| 1305 | #if defined(FIRST) |
| 1306 | template <typename alpha> struct Bravo { |
| 1307 | void charlie(bool delta = false) {} |
| 1308 | }; |
| 1309 | typedef Bravo<char> echo; |
| 1310 | echo foxtrot; |
| 1311 | #elif defined(SECOND) |
| 1312 | template <typename alpha> struct Bravo { |
| 1313 | void charlie(bool delta = (false)) {} |
| 1314 | }; |
| 1315 | typedef Bravo<char> echo; |
| 1316 | echo foxtrot; |
| 1317 | #else |
| 1318 | Bravo<char> golf; |
| 1319 | // expected-error@second.h:* {{'VarDecl::Bravo' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'charlie' with 1st parameter with a default argument}} |
| 1320 | // expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}} |
| 1321 | #endif |
| 1322 | } |
| 1323 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1324 | // Interesting cases that should not cause errors. struct S should not error |
| 1325 | // while struct T should error at the access specifier mismatch at the end. |
| 1326 | namespace AllDecls { |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1327 | #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \ |
| 1328 | typedef int INT; \ |
| 1329 | struct NAME { \ |
| 1330 | public: \ |
| 1331 | private: \ |
| 1332 | protected: \ |
| 1333 | static_assert(1 == 1, "Message"); \ |
| 1334 | static_assert(2 == 2); \ |
| 1335 | \ |
| 1336 | int x; \ |
| 1337 | double y; \ |
| 1338 | \ |
| 1339 | INT z; \ |
| 1340 | \ |
| 1341 | unsigned a : 1; \ |
| 1342 | unsigned b : 2 * 2 + 5 / 2; \ |
| 1343 | \ |
| 1344 | mutable int c = sizeof(x + y); \ |
| 1345 | \ |
| 1346 | void method() {} \ |
| 1347 | static void static_method() {} \ |
| 1348 | virtual void virtual_method() {} \ |
| 1349 | virtual void pure_virtual_method() = 0; \ |
| 1350 | inline void inline_method() {} \ |
| 1351 | void volatile_method() volatile {} \ |
| 1352 | void const_method() const {} \ |
| 1353 | \ |
| 1354 | typedef int typedef_int; \ |
| 1355 | using using_int = int; \ |
| 1356 | \ |
| 1357 | void method_one_arg(int x) {} \ |
| 1358 | void method_one_arg_default_argument(int x = 5 + 5) {} \ |
| 1359 | void method_decayed_type(int x[5]) {} \ |
| 1360 | \ |
| 1361 | int constant_arr[5]; \ |
| 1362 | \ |
| 1363 | ACCESS: \ |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1364 | }; |
| 1365 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1366 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1367 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1368 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1369 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1370 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 1371 | S *s; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1372 | #endif |
| 1373 | |
| 1374 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1375 | CREATE_ALL_DECL_STRUCT(T, private) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1376 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1377 | CREATE_ALL_DECL_STRUCT(T, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1378 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 1379 | T *t; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1380 | // expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1381 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1382 | #endif |
| 1383 | } |
| 1384 | |
| 1385 | namespace FriendFunction { |
| 1386 | #if defined(FIRST) |
| 1387 | void F(int = 0); |
| 1388 | struct S { friend void F(int); }; |
| 1389 | #elif defined(SECOND) |
| 1390 | void F(int); |
| 1391 | struct S { friend void F(int); }; |
| 1392 | #else |
| 1393 | S s; |
| 1394 | #endif |
| 1395 | |
| 1396 | #if defined(FIRST) |
| 1397 | void G(int = 0); |
| 1398 | struct T { |
| 1399 | friend void G(int); |
| 1400 | |
| 1401 | private: |
| 1402 | }; |
| 1403 | #elif defined(SECOND) |
| 1404 | void G(int); |
| 1405 | struct T { |
| 1406 | friend void G(int); |
| 1407 | |
| 1408 | public: |
| 1409 | }; |
| 1410 | #else |
| 1411 | T t; |
| 1412 | // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1413 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1414 | #endif |
| 1415 | } // namespace FriendFunction |
| 1416 | |
| 1417 | namespace ImplicitDecl { |
| 1418 | #if defined(FIRST) |
| 1419 | struct S { }; |
| 1420 | void S_Constructors() { |
| 1421 | // Trigger creation of implicit contructors |
| 1422 | S foo; |
| 1423 | S bar = foo; |
| 1424 | S baz(bar); |
| 1425 | } |
| 1426 | #elif defined(SECOND) |
| 1427 | struct S { }; |
| 1428 | #else |
| 1429 | S s; |
| 1430 | #endif |
| 1431 | |
| 1432 | #if defined(FIRST) |
| 1433 | struct T { |
| 1434 | private: |
| 1435 | }; |
| 1436 | void T_Constructors() { |
| 1437 | // Trigger creation of implicit contructors |
| 1438 | T foo; |
| 1439 | T bar = foo; |
| 1440 | T baz(bar); |
| 1441 | } |
| 1442 | #elif defined(SECOND) |
| 1443 | struct T { |
| 1444 | public: |
| 1445 | }; |
| 1446 | #else |
| 1447 | T t; |
| 1448 | // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} |
| 1449 | // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}} |
| 1450 | #endif |
| 1451 | |
| 1452 | } // namespace ImplicitDelc |
| 1453 | |
| 1454 | namespace TemplatedClass { |
| 1455 | #if defined(FIRST) |
| 1456 | template <class> |
| 1457 | struct S {}; |
| 1458 | #elif defined(SECOND) |
| 1459 | template <class> |
| 1460 | struct S {}; |
| 1461 | #else |
| 1462 | S<int> s; |
| 1463 | #endif |
| 1464 | |
| 1465 | #if defined(FIRST) |
| 1466 | template <class> |
| 1467 | struct T { |
| 1468 | private: |
| 1469 | }; |
| 1470 | #elif defined(SECOND) |
| 1471 | template <class> |
| 1472 | struct T { |
| 1473 | public: |
| 1474 | }; |
| 1475 | #else |
| 1476 | T<int> t; |
| 1477 | // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1478 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1479 | #endif |
| 1480 | } // namespace TemplatedClass |
| 1481 | |
| 1482 | namespace TemplateClassWithField { |
| 1483 | #if defined(FIRST) |
| 1484 | template <class A> |
| 1485 | struct S { |
| 1486 | A a; |
| 1487 | }; |
| 1488 | #elif defined(SECOND) |
| 1489 | template <class A> |
| 1490 | struct S { |
| 1491 | A a; |
| 1492 | }; |
| 1493 | #else |
| 1494 | S<int> s; |
| 1495 | #endif |
| 1496 | |
| 1497 | #if defined(FIRST) |
| 1498 | template <class A> |
| 1499 | struct T { |
| 1500 | A a; |
| 1501 | |
| 1502 | private: |
| 1503 | }; |
| 1504 | #elif defined(SECOND) |
| 1505 | template <class A> |
| 1506 | struct T { |
| 1507 | A a; |
| 1508 | |
| 1509 | public: |
| 1510 | }; |
| 1511 | #else |
| 1512 | T<int> t; |
| 1513 | // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1514 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1515 | #endif |
| 1516 | } // namespace TemplateClassWithField |
| 1517 | |
| 1518 | namespace TemplateClassWithTemplateField { |
| 1519 | #if defined(FIRST) |
| 1520 | template <class A> |
| 1521 | class WrapperS; |
| 1522 | template <class A> |
| 1523 | struct S { |
| 1524 | WrapperS<A> a; |
| 1525 | }; |
| 1526 | #elif defined(SECOND) |
| 1527 | template <class A> |
| 1528 | class WrapperS; |
| 1529 | template <class A> |
| 1530 | struct S { |
| 1531 | WrapperS<A> a; |
| 1532 | }; |
| 1533 | #else |
| 1534 | template <class A> |
| 1535 | class WrapperS{}; |
| 1536 | S<int> s; |
| 1537 | #endif |
| 1538 | |
| 1539 | #if defined(FIRST) |
| 1540 | template <class A> |
| 1541 | class WrapperT; |
| 1542 | template <class A> |
| 1543 | struct T { |
| 1544 | WrapperT<A> a; |
| 1545 | |
| 1546 | public: |
| 1547 | }; |
| 1548 | #elif defined(SECOND) |
| 1549 | template <class A> |
| 1550 | class WrapperT; |
| 1551 | template <class A> |
| 1552 | struct T { |
| 1553 | WrapperT<A> a; |
| 1554 | |
| 1555 | private: |
| 1556 | }; |
| 1557 | #else |
| 1558 | template <class A> |
| 1559 | class WrapperT{}; |
| 1560 | T<int> t; |
| 1561 | // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1562 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1563 | #endif |
| 1564 | } // namespace TemplateClassWithTemplateField |
| 1565 | |
| 1566 | namespace EnumWithForwardDeclaration { |
| 1567 | #if defined(FIRST) |
| 1568 | enum E : int; |
| 1569 | struct S { |
| 1570 | void get(E) {} |
| 1571 | }; |
| 1572 | #elif defined(SECOND) |
| 1573 | enum E : int { A, B }; |
| 1574 | struct S { |
| 1575 | void get(E) {} |
| 1576 | }; |
| 1577 | #else |
| 1578 | S s; |
| 1579 | #endif |
| 1580 | |
| 1581 | #if defined(FIRST) |
| 1582 | struct T { |
| 1583 | void get(E) {} |
| 1584 | public: |
| 1585 | }; |
| 1586 | #elif defined(SECOND) |
| 1587 | struct T { |
| 1588 | void get(E) {} |
| 1589 | private: |
| 1590 | }; |
| 1591 | #else |
| 1592 | T t; |
| 1593 | // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1594 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1595 | #endif |
| 1596 | } // namespace EnumWithForwardDeclaration |
| 1597 | |
| 1598 | namespace StructWithForwardDeclaration { |
| 1599 | #if defined(FIRST) |
| 1600 | struct P {}; |
| 1601 | struct S { |
| 1602 | struct P *ptr; |
| 1603 | }; |
| 1604 | #elif defined(SECOND) |
| 1605 | struct S { |
| 1606 | struct P *ptr; |
| 1607 | }; |
| 1608 | #else |
| 1609 | S s; |
| 1610 | #endif |
| 1611 | |
| 1612 | #if defined(FIRST) |
| 1613 | struct Q {}; |
| 1614 | struct T { |
| 1615 | struct Q *ptr; |
| 1616 | public: |
| 1617 | }; |
| 1618 | #elif defined(SECOND) |
| 1619 | struct T { |
| 1620 | struct Q *ptr; |
| 1621 | private: |
| 1622 | }; |
| 1623 | #else |
| 1624 | T t; |
| 1625 | // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1626 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1627 | #endif |
| 1628 | } // namespace StructWithForwardDeclaration |
| 1629 | |
| 1630 | namespace StructWithForwardDeclarationNoDefinition { |
| 1631 | #if defined(FIRST) |
| 1632 | struct P; |
| 1633 | struct S { |
| 1634 | struct P *ptr; |
| 1635 | }; |
| 1636 | #elif defined(SECOND) |
| 1637 | struct S { |
| 1638 | struct P *ptr; |
| 1639 | }; |
| 1640 | #else |
| 1641 | S s; |
| 1642 | #endif |
| 1643 | |
| 1644 | #if defined(FIRST) |
| 1645 | struct Q; |
| 1646 | struct T { |
| 1647 | struct Q *ptr; |
| 1648 | |
| 1649 | public: |
| 1650 | }; |
| 1651 | #elif defined(SECOND) |
| 1652 | struct T { |
| 1653 | struct Q *ptr; |
| 1654 | |
| 1655 | private: |
| 1656 | }; |
| 1657 | #else |
| 1658 | T t; |
| 1659 | // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1660 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1661 | #endif |
| 1662 | } // namespace StructWithForwardDeclarationNoDefinition |
| 1663 | |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1664 | namespace LateParsedDefaultArgument { |
| 1665 | #if defined(FIRST) |
| 1666 | template <typename T> |
| 1667 | struct S { |
| 1668 | struct R { |
| 1669 | void foo(T x = 0) {} |
| 1670 | }; |
| 1671 | }; |
| 1672 | #elif defined(SECOND) |
| 1673 | #else |
| 1674 | void run() { |
| 1675 | S<int>::R().foo(); |
| 1676 | } |
| 1677 | #endif |
| 1678 | } |
| 1679 | |
| 1680 | namespace LateParsedDefaultArgument { |
| 1681 | #if defined(FIRST) |
| 1682 | template <typename alpha> struct Bravo { |
| 1683 | void charlie(bool delta = false) {} |
| 1684 | }; |
| 1685 | typedef Bravo<char> echo; |
| 1686 | echo foxtrot; |
| 1687 | |
| 1688 | Bravo<char> golf; |
| 1689 | #elif defined(SECOND) |
| 1690 | #else |
| 1691 | #endif |
| 1692 | } |
| 1693 | |
Richard Trieu | 157ed94 | 2017-04-28 22:03:28 +0000 | [diff] [blame] | 1694 | namespace DifferentParameterNameInTemplate { |
| 1695 | #if defined(FIRST) || defined(SECOND) |
| 1696 | template <typename T> |
| 1697 | struct S { |
| 1698 | typedef T Type; |
| 1699 | |
| 1700 | static void Run(const Type *name_one); |
| 1701 | }; |
| 1702 | |
| 1703 | template <typename T> |
| 1704 | void S<T>::Run(const T *name_two) {} |
| 1705 | |
| 1706 | template <typename T> |
| 1707 | struct Foo { |
| 1708 | ~Foo() { Handler::Run(nullptr); } |
| 1709 | Foo() {} |
| 1710 | |
| 1711 | class Handler : public S<T> {}; |
| 1712 | |
| 1713 | void Get(typename Handler::Type *x = nullptr) {} |
| 1714 | void Add() { Handler::Run(nullptr); } |
| 1715 | }; |
| 1716 | #endif |
| 1717 | |
| 1718 | #if defined(FIRST) |
| 1719 | struct Beta; |
| 1720 | |
| 1721 | struct Alpha { |
| 1722 | Alpha(); |
| 1723 | void Go() { betas.Get(); } |
| 1724 | Foo<Beta> betas; |
| 1725 | }; |
| 1726 | |
| 1727 | #elif defined(SECOND) |
| 1728 | struct Beta {}; |
| 1729 | |
| 1730 | struct BetaHelper { |
| 1731 | void add_Beta() { betas.Add(); } |
| 1732 | Foo<Beta> betas; |
| 1733 | }; |
| 1734 | |
| 1735 | #else |
| 1736 | Alpha::Alpha() {} |
| 1737 | #endif |
| 1738 | } |
| 1739 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1740 | namespace ParameterTest { |
| 1741 | #if defined(FIRST) |
| 1742 | class X {}; |
| 1743 | template <typename G> |
| 1744 | class S { |
| 1745 | public: |
| 1746 | typedef G Type; |
| 1747 | static inline G *Foo(const G *a, int * = nullptr); |
| 1748 | }; |
| 1749 | |
| 1750 | template<typename G> |
| 1751 | G* S<G>::Foo(const G* aaaa, int*) {} |
| 1752 | #elif defined(SECOND) |
| 1753 | template <typename G> |
| 1754 | class S { |
| 1755 | public: |
| 1756 | typedef G Type; |
| 1757 | static inline G *Foo(const G *a, int * = nullptr); |
| 1758 | }; |
| 1759 | |
| 1760 | template<typename G> |
| 1761 | G* S<G>::Foo(const G* asdf, int*) {} |
| 1762 | #else |
| 1763 | S<X> s; |
| 1764 | #endif |
| 1765 | } |
| 1766 | |
Richard Trieu | b35ef2a | 2017-05-09 03:24:34 +0000 | [diff] [blame] | 1767 | namespace MultipleTypedefs { |
| 1768 | #if defined(FIRST) |
| 1769 | typedef int B1; |
| 1770 | typedef B1 A1; |
| 1771 | struct S1 { |
| 1772 | A1 x; |
| 1773 | }; |
| 1774 | #elif defined(SECOND) |
| 1775 | typedef int A1; |
| 1776 | struct S1 { |
| 1777 | A1 x; |
| 1778 | }; |
| 1779 | #else |
| 1780 | S1 s1; |
| 1781 | #endif |
| 1782 | |
| 1783 | #if defined(FIRST) |
| 1784 | struct T2 { int x; }; |
| 1785 | typedef T2 B2; |
| 1786 | typedef B2 A2; |
| 1787 | struct S2 { |
| 1788 | T2 x; |
| 1789 | }; |
| 1790 | #elif defined(SECOND) |
| 1791 | struct T2 { int x; }; |
| 1792 | typedef T2 A2; |
| 1793 | struct S2 { |
| 1794 | T2 x; |
| 1795 | }; |
| 1796 | #else |
| 1797 | S2 s2; |
| 1798 | #endif |
Richard Trieu | 3e03d3e | 2017-06-29 22:53:04 +0000 | [diff] [blame] | 1799 | |
| 1800 | #if defined(FIRST) |
| 1801 | using A3 = const int; |
| 1802 | using B3 = volatile A3; |
| 1803 | struct S3 { |
| 1804 | B3 x = 1; |
| 1805 | }; |
| 1806 | #elif defined(SECOND) |
| 1807 | using A3 = volatile const int; |
| 1808 | using B3 = A3; |
| 1809 | struct S3 { |
| 1810 | B3 x = 1; |
| 1811 | }; |
| 1812 | #else |
| 1813 | S3 s3; |
| 1814 | #endif |
Richard Trieu | b35ef2a | 2017-05-09 03:24:34 +0000 | [diff] [blame] | 1815 | } |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1816 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1817 | // Keep macros contained to one file. |
| 1818 | #ifdef FIRST |
| 1819 | #undef FIRST |
| 1820 | #endif |
| 1821 | #ifdef SECOND |
| 1822 | #undef SECOND |
| 1823 | #endif |