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; |
| 489 | // TODO: This should produce an error. |
| 490 | #endif |
| 491 | |
| 492 | #if defined(FIRST) |
| 493 | struct S13 { |
| 494 | void A(int x = 1 + 0) {} |
| 495 | }; |
| 496 | #elif defined(SECOND) |
| 497 | struct S13 { |
| 498 | void A(int x = 1) {} |
| 499 | }; |
| 500 | #else |
| 501 | S13 s13; |
| 502 | // TODO: This should produce an error. |
| 503 | #endif |
| 504 | |
| 505 | #if defined(FIRST) |
| 506 | struct S14 { |
| 507 | void A(int x[2]) {} |
| 508 | }; |
| 509 | #elif defined(SECOND) |
| 510 | struct S14 { |
| 511 | void A(int x[3]) {} |
| 512 | }; |
| 513 | #else |
| 514 | S14 s14; |
| 515 | // 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]'}} |
| 516 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}} |
| 517 | #endif |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 518 | } // namespace Method |
| 519 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 520 | // Naive parsing of AST can lead to cycles in processing. Ensure |
| 521 | // self-references don't trigger an endless cycles of AST node processing. |
| 522 | namespace SelfReference { |
| 523 | #if defined(FIRST) |
| 524 | template <template <int> class T> class Wrapper {}; |
| 525 | |
| 526 | template <int N> class S { |
| 527 | S(Wrapper<::SelfReference::S> &Ref) {} |
| 528 | }; |
| 529 | |
| 530 | struct Xx { |
| 531 | struct Yy { |
| 532 | }; |
| 533 | }; |
| 534 | |
| 535 | Xx::Xx::Xx::Yy yy; |
| 536 | |
| 537 | namespace NNS { |
| 538 | template <typename> struct Foo; |
| 539 | template <template <class> class T = NNS::Foo> |
| 540 | struct NestedNamespaceSpecifier {}; |
| 541 | } |
| 542 | #endif |
| 543 | } // namespace SelfReference |
| 544 | |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 545 | namespace TypeDef { |
| 546 | #if defined(FIRST) |
| 547 | struct S1 { |
| 548 | typedef int a; |
| 549 | }; |
| 550 | #elif defined(SECOND) |
| 551 | struct S1 { |
| 552 | typedef double a; |
| 553 | }; |
| 554 | #else |
| 555 | S1 s1; |
| 556 | // expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}} |
| 557 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 558 | #endif |
| 559 | |
| 560 | #if defined(FIRST) |
| 561 | struct S2 { |
| 562 | typedef int a; |
| 563 | }; |
| 564 | #elif defined(SECOND) |
| 565 | struct S2 { |
| 566 | typedef int b; |
| 567 | }; |
| 568 | #else |
| 569 | S2 s2; |
| 570 | // expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}} |
| 571 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 572 | #endif |
| 573 | |
| 574 | #if defined(FIRST) |
| 575 | typedef int T; |
| 576 | struct S3 { |
| 577 | typedef T a; |
| 578 | }; |
| 579 | #elif defined(SECOND) |
| 580 | typedef double T; |
| 581 | struct S3 { |
| 582 | typedef T a; |
| 583 | }; |
| 584 | #else |
| 585 | S3 s3; |
| 586 | // expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}} |
| 587 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 588 | #endif |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 589 | |
| 590 | #if defined(FIRST) |
| 591 | struct S4 { |
| 592 | typedef int a; |
| 593 | typedef int b; |
| 594 | }; |
| 595 | #elif defined(SECOND) |
| 596 | struct S4 { |
| 597 | typedef int b; |
| 598 | typedef int a; |
| 599 | }; |
| 600 | #else |
| 601 | S4 s4; |
| 602 | // expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}} |
| 603 | // expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}} |
| 604 | #endif |
| 605 | |
| 606 | #if defined(FIRST) |
| 607 | struct S5 { |
| 608 | typedef int a; |
| 609 | typedef int b; |
| 610 | int x; |
| 611 | }; |
| 612 | #elif defined(SECOND) |
| 613 | struct S5 { |
| 614 | int x; |
| 615 | typedef int b; |
| 616 | typedef int a; |
| 617 | }; |
| 618 | #else |
| 619 | S5 s5; |
| 620 | // expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} |
| 621 | // expected-note@first.h:* {{but in 'FirstModule' found typedef}} |
| 622 | #endif |
| 623 | |
| 624 | #if defined(FIRST) |
| 625 | typedef float F; |
| 626 | struct S6 { |
| 627 | typedef int a; |
| 628 | typedef F b; |
| 629 | }; |
| 630 | #elif defined(SECOND) |
| 631 | struct S6 { |
| 632 | typedef int a; |
| 633 | typedef float b; |
| 634 | }; |
| 635 | #else |
| 636 | S6 s6; |
| 637 | // 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'}} |
| 638 | // expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}} |
| 639 | #endif |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 640 | } // namespace TypeDef |
| 641 | |
| 642 | namespace Using { |
| 643 | #if defined(FIRST) |
| 644 | struct S1 { |
| 645 | using a = int; |
| 646 | }; |
| 647 | #elif defined(SECOND) |
| 648 | struct S1 { |
| 649 | using a = double; |
| 650 | }; |
| 651 | #else |
| 652 | S1 s1; |
| 653 | // expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}} |
| 654 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 655 | #endif |
| 656 | |
| 657 | #if defined(FIRST) |
| 658 | struct S2 { |
| 659 | using a = int; |
| 660 | }; |
| 661 | #elif defined(SECOND) |
| 662 | struct S2 { |
| 663 | using b = int; |
| 664 | }; |
| 665 | #else |
| 666 | S2 s2; |
| 667 | // expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}} |
| 668 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 669 | #endif |
| 670 | |
| 671 | #if defined(FIRST) |
| 672 | typedef int T; |
| 673 | struct S3 { |
| 674 | using a = T; |
| 675 | }; |
| 676 | #elif defined(SECOND) |
| 677 | typedef double T; |
| 678 | struct S3 { |
| 679 | using a = T; |
| 680 | }; |
| 681 | #else |
| 682 | S3 s3; |
| 683 | // expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}} |
| 684 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 685 | #endif |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 686 | |
| 687 | #if defined(FIRST) |
| 688 | struct S4 { |
| 689 | using a = int; |
| 690 | using b = int; |
| 691 | }; |
| 692 | #elif defined(SECOND) |
| 693 | struct S4 { |
| 694 | using b = int; |
| 695 | using a = int; |
| 696 | }; |
| 697 | #else |
| 698 | S4 s4; |
| 699 | // expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}} |
| 700 | // expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}} |
| 701 | #endif |
| 702 | |
| 703 | #if defined(FIRST) |
| 704 | struct S5 { |
| 705 | using a = int; |
| 706 | using b = int; |
| 707 | int x; |
| 708 | }; |
| 709 | #elif defined(SECOND) |
| 710 | struct S5 { |
| 711 | int x; |
| 712 | using b = int; |
| 713 | using a = int; |
| 714 | }; |
| 715 | #else |
| 716 | S5 s5; |
| 717 | // expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}} |
| 718 | // expected-note@first.h:* {{but in 'FirstModule' found type alias}} |
| 719 | #endif |
| 720 | |
| 721 | #if defined(FIRST) |
| 722 | typedef float F; |
| 723 | struct S6 { |
| 724 | using a = int; |
| 725 | using b = F; |
| 726 | }; |
| 727 | #elif defined(SECOND) |
| 728 | struct S6 { |
| 729 | using a = int; |
| 730 | using b = float; |
| 731 | }; |
| 732 | #else |
| 733 | S6 s6; |
| 734 | // 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'}} |
| 735 | // expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}} |
| 736 | #endif |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 737 | } // namespace Using |
| 738 | |
Richard Trieu | 58bb7bd | 2017-05-17 02:29:02 +0000 | [diff] [blame] | 739 | namespace RecordType { |
| 740 | #if defined(FIRST) |
| 741 | struct B1 {}; |
| 742 | struct S1 { |
| 743 | B1 x; |
| 744 | }; |
| 745 | #elif defined(SECOND) |
| 746 | struct A1 {}; |
| 747 | struct S1 { |
| 748 | A1 x; |
| 749 | }; |
| 750 | #else |
| 751 | S1 s1; |
| 752 | // expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}} |
| 753 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 754 | #endif |
| 755 | } |
| 756 | |
| 757 | namespace DependentType { |
| 758 | #if defined(FIRST) |
| 759 | template <class T> |
| 760 | class S1 { |
| 761 | typename T::typeA x; |
| 762 | }; |
| 763 | #elif defined(SECOND) |
| 764 | template <class T> |
| 765 | class S1 { |
| 766 | typename T::typeB x; |
| 767 | }; |
| 768 | #else |
| 769 | template<class T> |
| 770 | using U1 = S1<T>; |
| 771 | // expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}} |
| 772 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 773 | #endif |
| 774 | } |
| 775 | |
| 776 | namespace ElaboratedType { |
| 777 | #if defined(FIRST) |
| 778 | namespace N1 { using type = double; } |
| 779 | struct S1 { |
| 780 | N1::type x; |
| 781 | }; |
| 782 | #elif defined(SECOND) |
| 783 | namespace N1 { using type = int; } |
| 784 | struct S1 { |
| 785 | N1::type x; |
| 786 | }; |
| 787 | #else |
| 788 | S1 s1; |
| 789 | // expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}} |
| 790 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 791 | #endif |
| 792 | } |
| 793 | |
| 794 | namespace Enum { |
| 795 | #if defined(FIRST) |
| 796 | enum A1 {}; |
| 797 | struct S1 { |
| 798 | A1 x; |
| 799 | }; |
| 800 | #elif defined(SECOND) |
| 801 | enum A2 {}; |
| 802 | struct S1 { |
| 803 | A2 x; |
| 804 | }; |
| 805 | #else |
| 806 | S1 s1; |
| 807 | // expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}} |
| 808 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 809 | #endif |
| 810 | } |
Hans Wennborg | 2270776 | 2017-04-12 16:40:26 +0000 | [diff] [blame] | 811 | |
Richard Trieu | ce81b19 | 2017-05-17 03:23:35 +0000 | [diff] [blame] | 812 | namespace NestedNamespaceSpecifier { |
| 813 | #if defined(FIRST) |
| 814 | namespace LevelA1 { |
| 815 | using Type = int; |
| 816 | } |
| 817 | |
| 818 | struct S1 { |
| 819 | LevelA1::Type x; |
| 820 | }; |
| 821 | # elif defined(SECOND) |
| 822 | namespace LevelB1 { |
| 823 | namespace LevelC1 { |
| 824 | using Type = int; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | struct S1 { |
| 829 | LevelB1::LevelC1::Type x; |
| 830 | }; |
| 831 | #else |
| 832 | S1 s1; |
| 833 | // 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')}} |
| 834 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}} |
| 835 | #endif |
| 836 | |
| 837 | #if defined(FIRST) |
| 838 | namespace LevelA2 { using Type = int; } |
| 839 | struct S2 { |
| 840 | LevelA2::Type x; |
| 841 | }; |
| 842 | # elif defined(SECOND) |
| 843 | struct S2 { |
| 844 | int x; |
| 845 | }; |
| 846 | #else |
| 847 | S2 s2; |
| 848 | // 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'}} |
| 849 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}} |
| 850 | #endif |
| 851 | |
| 852 | namespace LevelA3 { using Type = int; } |
| 853 | namespace LevelB3 { using Type = int; } |
| 854 | #if defined(FIRST) |
| 855 | struct S3 { |
| 856 | LevelA3::Type x; |
| 857 | }; |
| 858 | # elif defined(SECOND) |
| 859 | struct S3 { |
| 860 | LevelB3::Type x; |
| 861 | }; |
| 862 | #else |
| 863 | S3 s3; |
| 864 | // 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')}} |
| 865 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}} |
| 866 | #endif |
| 867 | |
| 868 | #if defined(FIRST) |
| 869 | struct TA4 { using Type = int; }; |
| 870 | struct S4 { |
| 871 | TA4::Type x; |
| 872 | }; |
| 873 | # elif defined(SECOND) |
| 874 | struct TB4 { using Type = int; }; |
| 875 | struct S4 { |
| 876 | TB4::Type x; |
| 877 | }; |
| 878 | #else |
| 879 | S4 s4; |
| 880 | // 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')}} |
| 881 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}} |
| 882 | #endif |
| 883 | |
| 884 | #if defined(FIRST) |
| 885 | struct T5 { using Type = int; }; |
| 886 | struct S5 { |
| 887 | T5::Type x; |
| 888 | }; |
| 889 | # elif defined(SECOND) |
| 890 | namespace T5 { using Type = int; }; |
| 891 | struct S5 { |
| 892 | T5::Type x; |
| 893 | }; |
| 894 | #else |
| 895 | S5 s5; |
| 896 | // 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')}} |
| 897 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}} |
| 898 | #endif |
| 899 | |
| 900 | #if defined(FIRST) |
| 901 | namespace N6 {using I = int;} |
| 902 | struct S6 { |
| 903 | NestedNamespaceSpecifier::N6::I x; |
| 904 | }; |
| 905 | # elif defined(SECOND) |
| 906 | using I = int; |
| 907 | struct S6 { |
| 908 | ::NestedNamespaceSpecifier::I x; |
| 909 | }; |
| 910 | #else |
| 911 | S6 s6; |
| 912 | // 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')}} |
| 913 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}} |
| 914 | #endif |
| 915 | |
| 916 | #if defined(FIRST) |
| 917 | template <class T, class U> |
| 918 | class S7 { |
| 919 | typename T::type *x = {}; |
| 920 | int z = x->T::foo(); |
| 921 | }; |
| 922 | #elif defined(SECOND) |
| 923 | template <class T, class U> |
| 924 | class S7 { |
| 925 | typename T::type *x = {}; |
| 926 | int z = x->U::foo(); |
| 927 | }; |
| 928 | #else |
| 929 | template <class T, class U> |
| 930 | using U7 = S7<T, U>; |
| 931 | // 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}} |
| 932 | // expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}} |
| 933 | #endif |
| 934 | |
| 935 | #if defined(FIRST) |
| 936 | template <class T> |
| 937 | class S8 { |
| 938 | int x = T::template X<int>::value; |
| 939 | }; |
| 940 | #elif defined(SECOND) |
| 941 | template <class T> |
| 942 | class S8 { |
| 943 | int x = T::template Y<int>::value; |
| 944 | }; |
| 945 | #else |
| 946 | template <class T> |
| 947 | using U8 = S8<T>; |
| 948 | // 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}} |
| 949 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}} |
| 950 | #endif |
| 951 | |
| 952 | #if defined(FIRST) |
| 953 | namespace N9 { using I = int; } |
| 954 | namespace O9 = N9; |
| 955 | struct S9 { |
| 956 | O9::I x; |
| 957 | }; |
| 958 | #elif defined(SECOND) |
| 959 | namespace N9 { using I = int; } |
| 960 | namespace P9 = N9; |
| 961 | struct S9 { |
| 962 | P9::I x; |
| 963 | }; |
| 964 | #else |
| 965 | S9 s9; |
| 966 | // 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')}} |
| 967 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}} |
| 968 | #endif |
| 969 | } |
| 970 | |
Richard Trieu | 96b4962 | 2017-05-31 00:31:58 +0000 | [diff] [blame] | 971 | namespace TemplateSpecializationType { |
| 972 | #if defined(FIRST) |
| 973 | template <class T1> struct U1 {}; |
| 974 | struct S1 { |
| 975 | U1<int> u; |
| 976 | }; |
| 977 | #elif defined(SECOND) |
| 978 | template <class T1, class T2> struct U1 {}; |
| 979 | struct S1 { |
| 980 | U1<int, int> u; |
| 981 | }; |
| 982 | #else |
| 983 | S1 s1; |
| 984 | // expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}} |
| 985 | // expected-note@second.h:* {{declaration of 'u' does not match}} |
| 986 | #endif |
| 987 | |
| 988 | #if defined(FIRST) |
| 989 | template <class T1> struct U2 {}; |
| 990 | struct S2 { |
| 991 | U2<int> u; |
| 992 | }; |
| 993 | #elif defined(SECOND) |
| 994 | template <class T1> struct V1 {}; |
| 995 | struct S2 { |
| 996 | V1<int> u; |
| 997 | }; |
| 998 | #else |
| 999 | S2 s2; |
| 1000 | // expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}} |
| 1001 | // expected-note@second.h:* {{declaration of 'u' does not match}} |
| 1002 | #endif |
| 1003 | } |
| 1004 | |
Richard Trieu | 3b261bb7 | 2017-06-13 22:21:18 +0000 | [diff] [blame] | 1005 | namespace TemplateArgument { |
| 1006 | #if defined(FIRST) |
| 1007 | template <class> struct U1{}; |
| 1008 | struct S1 { |
| 1009 | U1<int> x; |
| 1010 | }; |
| 1011 | #elif defined(SECOND) |
| 1012 | template <int> struct U1{}; |
| 1013 | struct S1 { |
| 1014 | U1<1> x; |
| 1015 | }; |
| 1016 | #else |
| 1017 | S1 s1; |
| 1018 | // expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}} |
| 1019 | // expected-note@second.h:* {{declaration of 'x' does not match}} |
| 1020 | #endif |
Richard Trieu | 1dcb405 | 2017-06-14 01:28:00 +0000 | [diff] [blame^] | 1021 | |
| 1022 | #if defined(FIRST) |
| 1023 | template <int> struct U2{}; |
| 1024 | struct S2 { |
| 1025 | using T = U2<2>; |
| 1026 | }; |
| 1027 | #elif defined(SECOND) |
| 1028 | template <int> struct U2{}; |
| 1029 | struct S2 { |
| 1030 | using T = U2<(2)>; |
| 1031 | }; |
| 1032 | #else |
| 1033 | S2 s2; |
| 1034 | // 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)>'}} |
| 1035 | // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}} |
| 1036 | #endif |
| 1037 | |
| 1038 | #if defined(FIRST) |
| 1039 | template <int> struct U3{}; |
| 1040 | struct S3 { |
| 1041 | using T = U3<2>; |
| 1042 | }; |
| 1043 | #elif defined(SECOND) |
| 1044 | template <int> struct U3{}; |
| 1045 | struct S3 { |
| 1046 | using T = U3<1 + 1>; |
| 1047 | }; |
| 1048 | #else |
| 1049 | S3 s3; |
| 1050 | // 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>'}} |
| 1051 | // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}} |
| 1052 | #endif |
| 1053 | |
Richard Trieu | 3b261bb7 | 2017-06-13 22:21:18 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1056 | // Interesting cases that should not cause errors. struct S should not error |
| 1057 | // while struct T should error at the access specifier mismatch at the end. |
| 1058 | namespace AllDecls { |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1059 | #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \ |
| 1060 | typedef int INT; \ |
| 1061 | struct NAME { \ |
| 1062 | public: \ |
| 1063 | private: \ |
| 1064 | protected: \ |
| 1065 | static_assert(1 == 1, "Message"); \ |
| 1066 | static_assert(2 == 2); \ |
| 1067 | \ |
| 1068 | int x; \ |
| 1069 | double y; \ |
| 1070 | \ |
| 1071 | INT z; \ |
| 1072 | \ |
| 1073 | unsigned a : 1; \ |
| 1074 | unsigned b : 2 * 2 + 5 / 2; \ |
| 1075 | \ |
| 1076 | mutable int c = sizeof(x + y); \ |
| 1077 | \ |
| 1078 | void method() {} \ |
| 1079 | static void static_method() {} \ |
| 1080 | virtual void virtual_method() {} \ |
| 1081 | virtual void pure_virtual_method() = 0; \ |
| 1082 | inline void inline_method() {} \ |
| 1083 | void volatile_method() volatile {} \ |
| 1084 | void const_method() const {} \ |
| 1085 | \ |
| 1086 | typedef int typedef_int; \ |
| 1087 | using using_int = int; \ |
| 1088 | \ |
| 1089 | void method_one_arg(int x) {} \ |
| 1090 | void method_one_arg_default_argument(int x = 5 + 5) {} \ |
| 1091 | void method_decayed_type(int x[5]) {} \ |
| 1092 | \ |
| 1093 | int constant_arr[5]; \ |
| 1094 | \ |
| 1095 | ACCESS: \ |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1096 | }; |
| 1097 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1098 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1099 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1100 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1101 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1102 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 1103 | S *s; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1104 | #endif |
| 1105 | |
| 1106 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1107 | CREATE_ALL_DECL_STRUCT(T, private) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1108 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1109 | CREATE_ALL_DECL_STRUCT(T, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1110 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 1111 | T *t; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1112 | // expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1113 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1114 | #endif |
| 1115 | } |
| 1116 | |
| 1117 | namespace FriendFunction { |
| 1118 | #if defined(FIRST) |
| 1119 | void F(int = 0); |
| 1120 | struct S { friend void F(int); }; |
| 1121 | #elif defined(SECOND) |
| 1122 | void F(int); |
| 1123 | struct S { friend void F(int); }; |
| 1124 | #else |
| 1125 | S s; |
| 1126 | #endif |
| 1127 | |
| 1128 | #if defined(FIRST) |
| 1129 | void G(int = 0); |
| 1130 | struct T { |
| 1131 | friend void G(int); |
| 1132 | |
| 1133 | private: |
| 1134 | }; |
| 1135 | #elif defined(SECOND) |
| 1136 | void G(int); |
| 1137 | struct T { |
| 1138 | friend void G(int); |
| 1139 | |
| 1140 | public: |
| 1141 | }; |
| 1142 | #else |
| 1143 | T t; |
| 1144 | // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1145 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1146 | #endif |
| 1147 | } // namespace FriendFunction |
| 1148 | |
| 1149 | namespace ImplicitDecl { |
| 1150 | #if defined(FIRST) |
| 1151 | struct S { }; |
| 1152 | void S_Constructors() { |
| 1153 | // Trigger creation of implicit contructors |
| 1154 | S foo; |
| 1155 | S bar = foo; |
| 1156 | S baz(bar); |
| 1157 | } |
| 1158 | #elif defined(SECOND) |
| 1159 | struct S { }; |
| 1160 | #else |
| 1161 | S s; |
| 1162 | #endif |
| 1163 | |
| 1164 | #if defined(FIRST) |
| 1165 | struct T { |
| 1166 | private: |
| 1167 | }; |
| 1168 | void T_Constructors() { |
| 1169 | // Trigger creation of implicit contructors |
| 1170 | T foo; |
| 1171 | T bar = foo; |
| 1172 | T baz(bar); |
| 1173 | } |
| 1174 | #elif defined(SECOND) |
| 1175 | struct T { |
| 1176 | public: |
| 1177 | }; |
| 1178 | #else |
| 1179 | T t; |
| 1180 | // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} |
| 1181 | // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}} |
| 1182 | #endif |
| 1183 | |
| 1184 | } // namespace ImplicitDelc |
| 1185 | |
| 1186 | namespace TemplatedClass { |
| 1187 | #if defined(FIRST) |
| 1188 | template <class> |
| 1189 | struct S {}; |
| 1190 | #elif defined(SECOND) |
| 1191 | template <class> |
| 1192 | struct S {}; |
| 1193 | #else |
| 1194 | S<int> s; |
| 1195 | #endif |
| 1196 | |
| 1197 | #if defined(FIRST) |
| 1198 | template <class> |
| 1199 | struct T { |
| 1200 | private: |
| 1201 | }; |
| 1202 | #elif defined(SECOND) |
| 1203 | template <class> |
| 1204 | struct T { |
| 1205 | public: |
| 1206 | }; |
| 1207 | #else |
| 1208 | T<int> t; |
| 1209 | // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1210 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1211 | #endif |
| 1212 | } // namespace TemplatedClass |
| 1213 | |
| 1214 | namespace TemplateClassWithField { |
| 1215 | #if defined(FIRST) |
| 1216 | template <class A> |
| 1217 | struct S { |
| 1218 | A a; |
| 1219 | }; |
| 1220 | #elif defined(SECOND) |
| 1221 | template <class A> |
| 1222 | struct S { |
| 1223 | A a; |
| 1224 | }; |
| 1225 | #else |
| 1226 | S<int> s; |
| 1227 | #endif |
| 1228 | |
| 1229 | #if defined(FIRST) |
| 1230 | template <class A> |
| 1231 | struct T { |
| 1232 | A a; |
| 1233 | |
| 1234 | private: |
| 1235 | }; |
| 1236 | #elif defined(SECOND) |
| 1237 | template <class A> |
| 1238 | struct T { |
| 1239 | A a; |
| 1240 | |
| 1241 | public: |
| 1242 | }; |
| 1243 | #else |
| 1244 | T<int> t; |
| 1245 | // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 1246 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 1247 | #endif |
| 1248 | } // namespace TemplateClassWithField |
| 1249 | |
| 1250 | namespace TemplateClassWithTemplateField { |
| 1251 | #if defined(FIRST) |
| 1252 | template <class A> |
| 1253 | class WrapperS; |
| 1254 | template <class A> |
| 1255 | struct S { |
| 1256 | WrapperS<A> a; |
| 1257 | }; |
| 1258 | #elif defined(SECOND) |
| 1259 | template <class A> |
| 1260 | class WrapperS; |
| 1261 | template <class A> |
| 1262 | struct S { |
| 1263 | WrapperS<A> a; |
| 1264 | }; |
| 1265 | #else |
| 1266 | template <class A> |
| 1267 | class WrapperS{}; |
| 1268 | S<int> s; |
| 1269 | #endif |
| 1270 | |
| 1271 | #if defined(FIRST) |
| 1272 | template <class A> |
| 1273 | class WrapperT; |
| 1274 | template <class A> |
| 1275 | struct T { |
| 1276 | WrapperT<A> a; |
| 1277 | |
| 1278 | public: |
| 1279 | }; |
| 1280 | #elif defined(SECOND) |
| 1281 | template <class A> |
| 1282 | class WrapperT; |
| 1283 | template <class A> |
| 1284 | struct T { |
| 1285 | WrapperT<A> a; |
| 1286 | |
| 1287 | private: |
| 1288 | }; |
| 1289 | #else |
| 1290 | template <class A> |
| 1291 | class WrapperT{}; |
| 1292 | T<int> t; |
| 1293 | // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1294 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1295 | #endif |
| 1296 | } // namespace TemplateClassWithTemplateField |
| 1297 | |
| 1298 | namespace EnumWithForwardDeclaration { |
| 1299 | #if defined(FIRST) |
| 1300 | enum E : int; |
| 1301 | struct S { |
| 1302 | void get(E) {} |
| 1303 | }; |
| 1304 | #elif defined(SECOND) |
| 1305 | enum E : int { A, B }; |
| 1306 | struct S { |
| 1307 | void get(E) {} |
| 1308 | }; |
| 1309 | #else |
| 1310 | S s; |
| 1311 | #endif |
| 1312 | |
| 1313 | #if defined(FIRST) |
| 1314 | struct T { |
| 1315 | void get(E) {} |
| 1316 | public: |
| 1317 | }; |
| 1318 | #elif defined(SECOND) |
| 1319 | struct T { |
| 1320 | void get(E) {} |
| 1321 | private: |
| 1322 | }; |
| 1323 | #else |
| 1324 | T t; |
| 1325 | // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1326 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1327 | #endif |
| 1328 | } // namespace EnumWithForwardDeclaration |
| 1329 | |
| 1330 | namespace StructWithForwardDeclaration { |
| 1331 | #if defined(FIRST) |
| 1332 | struct P {}; |
| 1333 | struct S { |
| 1334 | struct P *ptr; |
| 1335 | }; |
| 1336 | #elif defined(SECOND) |
| 1337 | struct S { |
| 1338 | struct P *ptr; |
| 1339 | }; |
| 1340 | #else |
| 1341 | S s; |
| 1342 | #endif |
| 1343 | |
| 1344 | #if defined(FIRST) |
| 1345 | struct Q {}; |
| 1346 | struct T { |
| 1347 | struct Q *ptr; |
| 1348 | public: |
| 1349 | }; |
| 1350 | #elif defined(SECOND) |
| 1351 | struct T { |
| 1352 | struct Q *ptr; |
| 1353 | private: |
| 1354 | }; |
| 1355 | #else |
| 1356 | T t; |
| 1357 | // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1358 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1359 | #endif |
| 1360 | } // namespace StructWithForwardDeclaration |
| 1361 | |
| 1362 | namespace StructWithForwardDeclarationNoDefinition { |
| 1363 | #if defined(FIRST) |
| 1364 | struct P; |
| 1365 | struct S { |
| 1366 | struct P *ptr; |
| 1367 | }; |
| 1368 | #elif defined(SECOND) |
| 1369 | struct S { |
| 1370 | struct P *ptr; |
| 1371 | }; |
| 1372 | #else |
| 1373 | S s; |
| 1374 | #endif |
| 1375 | |
| 1376 | #if defined(FIRST) |
| 1377 | struct Q; |
| 1378 | struct T { |
| 1379 | struct Q *ptr; |
| 1380 | |
| 1381 | public: |
| 1382 | }; |
| 1383 | #elif defined(SECOND) |
| 1384 | struct T { |
| 1385 | struct Q *ptr; |
| 1386 | |
| 1387 | private: |
| 1388 | }; |
| 1389 | #else |
| 1390 | T t; |
| 1391 | // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 1392 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 1393 | #endif |
| 1394 | } // namespace StructWithForwardDeclarationNoDefinition |
| 1395 | |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame] | 1396 | namespace LateParsedDefaultArgument { |
| 1397 | #if defined(FIRST) |
| 1398 | template <typename T> |
| 1399 | struct S { |
| 1400 | struct R { |
| 1401 | void foo(T x = 0) {} |
| 1402 | }; |
| 1403 | }; |
| 1404 | #elif defined(SECOND) |
| 1405 | #else |
| 1406 | void run() { |
| 1407 | S<int>::R().foo(); |
| 1408 | } |
| 1409 | #endif |
| 1410 | } |
| 1411 | |
| 1412 | namespace LateParsedDefaultArgument { |
| 1413 | #if defined(FIRST) |
| 1414 | template <typename alpha> struct Bravo { |
| 1415 | void charlie(bool delta = false) {} |
| 1416 | }; |
| 1417 | typedef Bravo<char> echo; |
| 1418 | echo foxtrot; |
| 1419 | |
| 1420 | Bravo<char> golf; |
| 1421 | #elif defined(SECOND) |
| 1422 | #else |
| 1423 | #endif |
| 1424 | } |
| 1425 | |
Richard Trieu | 157ed94 | 2017-04-28 22:03:28 +0000 | [diff] [blame] | 1426 | namespace DifferentParameterNameInTemplate { |
| 1427 | #if defined(FIRST) || defined(SECOND) |
| 1428 | template <typename T> |
| 1429 | struct S { |
| 1430 | typedef T Type; |
| 1431 | |
| 1432 | static void Run(const Type *name_one); |
| 1433 | }; |
| 1434 | |
| 1435 | template <typename T> |
| 1436 | void S<T>::Run(const T *name_two) {} |
| 1437 | |
| 1438 | template <typename T> |
| 1439 | struct Foo { |
| 1440 | ~Foo() { Handler::Run(nullptr); } |
| 1441 | Foo() {} |
| 1442 | |
| 1443 | class Handler : public S<T> {}; |
| 1444 | |
| 1445 | void Get(typename Handler::Type *x = nullptr) {} |
| 1446 | void Add() { Handler::Run(nullptr); } |
| 1447 | }; |
| 1448 | #endif |
| 1449 | |
| 1450 | #if defined(FIRST) |
| 1451 | struct Beta; |
| 1452 | |
| 1453 | struct Alpha { |
| 1454 | Alpha(); |
| 1455 | void Go() { betas.Get(); } |
| 1456 | Foo<Beta> betas; |
| 1457 | }; |
| 1458 | |
| 1459 | #elif defined(SECOND) |
| 1460 | struct Beta {}; |
| 1461 | |
| 1462 | struct BetaHelper { |
| 1463 | void add_Beta() { betas.Add(); } |
| 1464 | Foo<Beta> betas; |
| 1465 | }; |
| 1466 | |
| 1467 | #else |
| 1468 | Alpha::Alpha() {} |
| 1469 | #endif |
| 1470 | } |
| 1471 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1472 | namespace ParameterTest { |
| 1473 | #if defined(FIRST) |
| 1474 | class X {}; |
| 1475 | template <typename G> |
| 1476 | class S { |
| 1477 | public: |
| 1478 | typedef G Type; |
| 1479 | static inline G *Foo(const G *a, int * = nullptr); |
| 1480 | }; |
| 1481 | |
| 1482 | template<typename G> |
| 1483 | G* S<G>::Foo(const G* aaaa, int*) {} |
| 1484 | #elif defined(SECOND) |
| 1485 | template <typename G> |
| 1486 | class S { |
| 1487 | public: |
| 1488 | typedef G Type; |
| 1489 | static inline G *Foo(const G *a, int * = nullptr); |
| 1490 | }; |
| 1491 | |
| 1492 | template<typename G> |
| 1493 | G* S<G>::Foo(const G* asdf, int*) {} |
| 1494 | #else |
| 1495 | S<X> s; |
| 1496 | #endif |
| 1497 | } |
| 1498 | |
Richard Trieu | b35ef2a | 2017-05-09 03:24:34 +0000 | [diff] [blame] | 1499 | namespace MultipleTypedefs { |
| 1500 | #if defined(FIRST) |
| 1501 | typedef int B1; |
| 1502 | typedef B1 A1; |
| 1503 | struct S1 { |
| 1504 | A1 x; |
| 1505 | }; |
| 1506 | #elif defined(SECOND) |
| 1507 | typedef int A1; |
| 1508 | struct S1 { |
| 1509 | A1 x; |
| 1510 | }; |
| 1511 | #else |
| 1512 | S1 s1; |
| 1513 | #endif |
| 1514 | |
| 1515 | #if defined(FIRST) |
| 1516 | struct T2 { int x; }; |
| 1517 | typedef T2 B2; |
| 1518 | typedef B2 A2; |
| 1519 | struct S2 { |
| 1520 | T2 x; |
| 1521 | }; |
| 1522 | #elif defined(SECOND) |
| 1523 | struct T2 { int x; }; |
| 1524 | typedef T2 A2; |
| 1525 | struct S2 { |
| 1526 | T2 x; |
| 1527 | }; |
| 1528 | #else |
| 1529 | S2 s2; |
| 1530 | #endif |
| 1531 | } |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 1532 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 1533 | // Keep macros contained to one file. |
| 1534 | #ifdef FIRST |
| 1535 | #undef FIRST |
| 1536 | #endif |
| 1537 | #ifdef SECOND |
| 1538 | #undef SECOND |
| 1539 | #endif |