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 | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 278 | } // namespace Field |
| 279 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 280 | namespace Method { |
| 281 | #if defined(FIRST) |
| 282 | struct S1 { |
| 283 | void A() {} |
| 284 | }; |
| 285 | #elif defined(SECOND) |
| 286 | struct S1 { |
| 287 | private: |
| 288 | void A() {} |
| 289 | }; |
| 290 | #else |
| 291 | S1 s1; |
| 292 | // expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 293 | // expected-note@first.h:* {{but in 'FirstModule' found method}} |
| 294 | #endif |
| 295 | |
| 296 | #if defined(FIRST) |
| 297 | struct S2 { |
| 298 | void A() {} |
| 299 | void B() {} |
| 300 | }; |
| 301 | #elif defined(SECOND) |
| 302 | struct S2 { |
| 303 | void B() {} |
| 304 | void A() {} |
| 305 | }; |
| 306 | #else |
| 307 | S2 s2; |
| 308 | // expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}} |
| 309 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A'}} |
| 310 | #endif |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 311 | |
| 312 | #if defined(FIRST) |
| 313 | struct S3 { |
| 314 | static void A() {} |
Richard Trieu | f4b54fe | 2017-03-04 03:04:15 +0000 | [diff] [blame] | 315 | void A(int) {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 316 | }; |
| 317 | #elif defined(SECOND) |
| 318 | struct S3 { |
Richard Trieu | f4b54fe | 2017-03-04 03:04:15 +0000 | [diff] [blame] | 319 | void A(int) {} |
| 320 | static void A() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 321 | }; |
| 322 | #else |
| 323 | S3 s3; |
| 324 | // 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}} |
| 325 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}} |
| 326 | #endif |
| 327 | |
| 328 | #if defined(FIRST) |
| 329 | struct S4 { |
| 330 | virtual void A() {} |
| 331 | void B() {} |
| 332 | }; |
| 333 | #elif defined(SECOND) |
| 334 | struct S4 { |
| 335 | void A() {} |
| 336 | virtual void B() {} |
| 337 | }; |
| 338 | #else |
| 339 | S4 s4; |
| 340 | // 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}} |
| 341 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}} |
| 342 | #endif |
| 343 | |
| 344 | #if defined(FIRST) |
| 345 | struct S5 { |
| 346 | virtual void A() = 0; |
| 347 | virtual void B() {}; |
| 348 | }; |
| 349 | #elif defined(SECOND) |
| 350 | struct S5 { |
| 351 | virtual void A() {} |
| 352 | virtual void B() = 0; |
| 353 | }; |
| 354 | #else |
| 355 | S5 *s5; |
| 356 | // expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}} |
| 357 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}} |
| 358 | #endif |
| 359 | |
| 360 | #if defined(FIRST) |
| 361 | struct S6 { |
| 362 | inline void A() {} |
| 363 | }; |
| 364 | #elif defined(SECOND) |
| 365 | struct S6 { |
| 366 | void A() {} |
| 367 | }; |
| 368 | #else |
| 369 | S6 s6; |
| 370 | // 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}} |
| 371 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}} |
| 372 | #endif |
| 373 | |
| 374 | #if defined(FIRST) |
| 375 | struct S7 { |
| 376 | void A() volatile {} |
| 377 | void A() {} |
| 378 | }; |
| 379 | #elif defined(SECOND) |
| 380 | struct S7 { |
| 381 | void A() {} |
| 382 | void A() volatile {} |
| 383 | }; |
| 384 | #else |
| 385 | S7 s7; |
| 386 | // 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}} |
| 387 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}} |
| 388 | #endif |
| 389 | |
| 390 | #if defined(FIRST) |
| 391 | struct S8 { |
| 392 | void A() const {} |
| 393 | void A() {} |
| 394 | }; |
| 395 | #elif defined(SECOND) |
| 396 | struct S8 { |
| 397 | void A() {} |
| 398 | void A() const {} |
| 399 | }; |
| 400 | #else |
| 401 | S8 s8; |
| 402 | // 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}} |
| 403 | // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}} |
| 404 | #endif |
| 405 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 406 | } // namespace Method |
| 407 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 408 | // Naive parsing of AST can lead to cycles in processing. Ensure |
| 409 | // self-references don't trigger an endless cycles of AST node processing. |
| 410 | namespace SelfReference { |
| 411 | #if defined(FIRST) |
| 412 | template <template <int> class T> class Wrapper {}; |
| 413 | |
| 414 | template <int N> class S { |
| 415 | S(Wrapper<::SelfReference::S> &Ref) {} |
| 416 | }; |
| 417 | |
| 418 | struct Xx { |
| 419 | struct Yy { |
| 420 | }; |
| 421 | }; |
| 422 | |
| 423 | Xx::Xx::Xx::Yy yy; |
| 424 | |
| 425 | namespace NNS { |
| 426 | template <typename> struct Foo; |
| 427 | template <template <class> class T = NNS::Foo> |
| 428 | struct NestedNamespaceSpecifier {}; |
| 429 | } |
| 430 | #endif |
| 431 | } // namespace SelfReference |
| 432 | |
Richard Trieu | 33562c2 | 2017-03-08 00:13:19 +0000 | [diff] [blame] | 433 | namespace TypeDef { |
| 434 | #if defined(FIRST) |
| 435 | struct S1 { |
| 436 | typedef int a; |
| 437 | }; |
| 438 | #elif defined(SECOND) |
| 439 | struct S1 { |
| 440 | typedef double a; |
| 441 | }; |
| 442 | #else |
| 443 | S1 s1; |
| 444 | // expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}} |
| 445 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 446 | #endif |
| 447 | |
| 448 | #if defined(FIRST) |
| 449 | struct S2 { |
| 450 | typedef int a; |
| 451 | }; |
| 452 | #elif defined(SECOND) |
| 453 | struct S2 { |
| 454 | typedef int b; |
| 455 | }; |
| 456 | #else |
| 457 | S2 s2; |
| 458 | // expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}} |
| 459 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 460 | #endif |
| 461 | |
| 462 | #if defined(FIRST) |
| 463 | typedef int T; |
| 464 | struct S3 { |
| 465 | typedef T a; |
| 466 | }; |
| 467 | #elif defined(SECOND) |
| 468 | typedef double T; |
| 469 | struct S3 { |
| 470 | typedef T a; |
| 471 | }; |
| 472 | #else |
| 473 | S3 s3; |
| 474 | // expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}} |
| 475 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 476 | #endif |
| 477 | } // namespace TypeDef |
| 478 | |
| 479 | namespace Using { |
| 480 | #if defined(FIRST) |
| 481 | struct S1 { |
| 482 | using a = int; |
| 483 | }; |
| 484 | #elif defined(SECOND) |
| 485 | struct S1 { |
| 486 | using a = double; |
| 487 | }; |
| 488 | #else |
| 489 | S1 s1; |
| 490 | // expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}} |
| 491 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 492 | #endif |
| 493 | |
| 494 | #if defined(FIRST) |
| 495 | struct S2 { |
| 496 | using a = int; |
| 497 | }; |
| 498 | #elif defined(SECOND) |
| 499 | struct S2 { |
| 500 | using b = int; |
| 501 | }; |
| 502 | #else |
| 503 | S2 s2; |
| 504 | // expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}} |
| 505 | // expected-note@second.h:* {{definition has no member 'a'}} |
| 506 | #endif |
| 507 | |
| 508 | #if defined(FIRST) |
| 509 | typedef int T; |
| 510 | struct S3 { |
| 511 | using a = T; |
| 512 | }; |
| 513 | #elif defined(SECOND) |
| 514 | typedef double T; |
| 515 | struct S3 { |
| 516 | using a = T; |
| 517 | }; |
| 518 | #else |
| 519 | S3 s3; |
| 520 | // expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}} |
| 521 | // expected-note@second.h:* {{declaration of 'a' does not match}} |
| 522 | #endif |
| 523 | } // namespace Using |
| 524 | |
Hans Wennborg | 2270776 | 2017-04-12 16:40:26 +0000 | [diff] [blame] | 525 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 526 | // Interesting cases that should not cause errors. struct S should not error |
| 527 | // while struct T should error at the access specifier mismatch at the end. |
| 528 | namespace AllDecls { |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame^] | 529 | #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \ |
| 530 | typedef int INT; \ |
| 531 | struct NAME { \ |
| 532 | public: \ |
| 533 | private: \ |
| 534 | protected: \ |
| 535 | static_assert(1 == 1, "Message"); \ |
| 536 | static_assert(2 == 2); \ |
| 537 | \ |
| 538 | int x; \ |
| 539 | double y; \ |
| 540 | \ |
| 541 | INT z; \ |
| 542 | \ |
| 543 | unsigned a : 1; \ |
| 544 | unsigned b : 2 * 2 + 5 / 2; \ |
| 545 | \ |
| 546 | mutable int c = sizeof(x + y); \ |
| 547 | \ |
| 548 | void method() {} \ |
| 549 | static void static_method() {} \ |
| 550 | virtual void virtual_method() {} \ |
| 551 | virtual void pure_virtual_method() = 0; \ |
| 552 | inline void inline_method() {} \ |
| 553 | void volatile_method() volatile {} \ |
| 554 | void const_method() const {} \ |
| 555 | \ |
| 556 | typedef int typedef_int; \ |
| 557 | using using_int = int; \ |
| 558 | \ |
| 559 | ACCESS: \ |
| 560 | }; |
| 561 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 562 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame^] | 563 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 564 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame^] | 565 | CREATE_ALL_DECL_STRUCT(S, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 566 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 567 | S *s; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 568 | #endif |
| 569 | |
| 570 | #if defined(FIRST) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame^] | 571 | CREATE_ALL_DECL_STRUCT(T, private) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 572 | #elif defined(SECOND) |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame^] | 573 | CREATE_ALL_DECL_STRUCT(T, public) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 574 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 575 | T *t; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 576 | // expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 577 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 578 | #endif |
| 579 | } |
| 580 | |
| 581 | namespace FriendFunction { |
| 582 | #if defined(FIRST) |
| 583 | void F(int = 0); |
| 584 | struct S { friend void F(int); }; |
| 585 | #elif defined(SECOND) |
| 586 | void F(int); |
| 587 | struct S { friend void F(int); }; |
| 588 | #else |
| 589 | S s; |
| 590 | #endif |
| 591 | |
| 592 | #if defined(FIRST) |
| 593 | void G(int = 0); |
| 594 | struct T { |
| 595 | friend void G(int); |
| 596 | |
| 597 | private: |
| 598 | }; |
| 599 | #elif defined(SECOND) |
| 600 | void G(int); |
| 601 | struct T { |
| 602 | friend void G(int); |
| 603 | |
| 604 | public: |
| 605 | }; |
| 606 | #else |
| 607 | T t; |
| 608 | // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 609 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 610 | #endif |
| 611 | } // namespace FriendFunction |
| 612 | |
| 613 | namespace ImplicitDecl { |
| 614 | #if defined(FIRST) |
| 615 | struct S { }; |
| 616 | void S_Constructors() { |
| 617 | // Trigger creation of implicit contructors |
| 618 | S foo; |
| 619 | S bar = foo; |
| 620 | S baz(bar); |
| 621 | } |
| 622 | #elif defined(SECOND) |
| 623 | struct S { }; |
| 624 | #else |
| 625 | S s; |
| 626 | #endif |
| 627 | |
| 628 | #if defined(FIRST) |
| 629 | struct T { |
| 630 | private: |
| 631 | }; |
| 632 | void T_Constructors() { |
| 633 | // Trigger creation of implicit contructors |
| 634 | T foo; |
| 635 | T bar = foo; |
| 636 | T baz(bar); |
| 637 | } |
| 638 | #elif defined(SECOND) |
| 639 | struct T { |
| 640 | public: |
| 641 | }; |
| 642 | #else |
| 643 | T t; |
| 644 | // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} |
| 645 | // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}} |
| 646 | #endif |
| 647 | |
| 648 | } // namespace ImplicitDelc |
| 649 | |
| 650 | namespace TemplatedClass { |
| 651 | #if defined(FIRST) |
| 652 | template <class> |
| 653 | struct S {}; |
| 654 | #elif defined(SECOND) |
| 655 | template <class> |
| 656 | struct S {}; |
| 657 | #else |
| 658 | S<int> s; |
| 659 | #endif |
| 660 | |
| 661 | #if defined(FIRST) |
| 662 | template <class> |
| 663 | struct T { |
| 664 | private: |
| 665 | }; |
| 666 | #elif defined(SECOND) |
| 667 | template <class> |
| 668 | struct T { |
| 669 | public: |
| 670 | }; |
| 671 | #else |
| 672 | T<int> t; |
| 673 | // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 674 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 675 | #endif |
| 676 | } // namespace TemplatedClass |
| 677 | |
| 678 | namespace TemplateClassWithField { |
| 679 | #if defined(FIRST) |
| 680 | template <class A> |
| 681 | struct S { |
| 682 | A a; |
| 683 | }; |
| 684 | #elif defined(SECOND) |
| 685 | template <class A> |
| 686 | struct S { |
| 687 | A a; |
| 688 | }; |
| 689 | #else |
| 690 | S<int> s; |
| 691 | #endif |
| 692 | |
| 693 | #if defined(FIRST) |
| 694 | template <class A> |
| 695 | struct T { |
| 696 | A a; |
| 697 | |
| 698 | private: |
| 699 | }; |
| 700 | #elif defined(SECOND) |
| 701 | template <class A> |
| 702 | struct T { |
| 703 | A a; |
| 704 | |
| 705 | public: |
| 706 | }; |
| 707 | #else |
| 708 | T<int> t; |
| 709 | // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 710 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 711 | #endif |
| 712 | } // namespace TemplateClassWithField |
| 713 | |
| 714 | namespace TemplateClassWithTemplateField { |
| 715 | #if defined(FIRST) |
| 716 | template <class A> |
| 717 | class WrapperS; |
| 718 | template <class A> |
| 719 | struct S { |
| 720 | WrapperS<A> a; |
| 721 | }; |
| 722 | #elif defined(SECOND) |
| 723 | template <class A> |
| 724 | class WrapperS; |
| 725 | template <class A> |
| 726 | struct S { |
| 727 | WrapperS<A> a; |
| 728 | }; |
| 729 | #else |
| 730 | template <class A> |
| 731 | class WrapperS{}; |
| 732 | S<int> s; |
| 733 | #endif |
| 734 | |
| 735 | #if defined(FIRST) |
| 736 | template <class A> |
| 737 | class WrapperT; |
| 738 | template <class A> |
| 739 | struct T { |
| 740 | WrapperT<A> a; |
| 741 | |
| 742 | public: |
| 743 | }; |
| 744 | #elif defined(SECOND) |
| 745 | template <class A> |
| 746 | class WrapperT; |
| 747 | template <class A> |
| 748 | struct T { |
| 749 | WrapperT<A> a; |
| 750 | |
| 751 | private: |
| 752 | }; |
| 753 | #else |
| 754 | template <class A> |
| 755 | class WrapperT{}; |
| 756 | T<int> t; |
| 757 | // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 758 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 759 | #endif |
| 760 | } // namespace TemplateClassWithTemplateField |
| 761 | |
| 762 | namespace EnumWithForwardDeclaration { |
| 763 | #if defined(FIRST) |
| 764 | enum E : int; |
| 765 | struct S { |
| 766 | void get(E) {} |
| 767 | }; |
| 768 | #elif defined(SECOND) |
| 769 | enum E : int { A, B }; |
| 770 | struct S { |
| 771 | void get(E) {} |
| 772 | }; |
| 773 | #else |
| 774 | S s; |
| 775 | #endif |
| 776 | |
| 777 | #if defined(FIRST) |
| 778 | struct T { |
| 779 | void get(E) {} |
| 780 | public: |
| 781 | }; |
| 782 | #elif defined(SECOND) |
| 783 | struct T { |
| 784 | void get(E) {} |
| 785 | private: |
| 786 | }; |
| 787 | #else |
| 788 | T t; |
| 789 | // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 790 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 791 | #endif |
| 792 | } // namespace EnumWithForwardDeclaration |
| 793 | |
| 794 | namespace StructWithForwardDeclaration { |
| 795 | #if defined(FIRST) |
| 796 | struct P {}; |
| 797 | struct S { |
| 798 | struct P *ptr; |
| 799 | }; |
| 800 | #elif defined(SECOND) |
| 801 | struct S { |
| 802 | struct P *ptr; |
| 803 | }; |
| 804 | #else |
| 805 | S s; |
| 806 | #endif |
| 807 | |
| 808 | #if defined(FIRST) |
| 809 | struct Q {}; |
| 810 | struct T { |
| 811 | struct Q *ptr; |
| 812 | public: |
| 813 | }; |
| 814 | #elif defined(SECOND) |
| 815 | struct T { |
| 816 | struct Q *ptr; |
| 817 | private: |
| 818 | }; |
| 819 | #else |
| 820 | T t; |
| 821 | // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 822 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 823 | #endif |
| 824 | } // namespace StructWithForwardDeclaration |
| 825 | |
| 826 | namespace StructWithForwardDeclarationNoDefinition { |
| 827 | #if defined(FIRST) |
| 828 | struct P; |
| 829 | struct S { |
| 830 | struct P *ptr; |
| 831 | }; |
| 832 | #elif defined(SECOND) |
| 833 | struct S { |
| 834 | struct P *ptr; |
| 835 | }; |
| 836 | #else |
| 837 | S s; |
| 838 | #endif |
| 839 | |
| 840 | #if defined(FIRST) |
| 841 | struct Q; |
| 842 | struct T { |
| 843 | struct Q *ptr; |
| 844 | |
| 845 | public: |
| 846 | }; |
| 847 | #elif defined(SECOND) |
| 848 | struct T { |
| 849 | struct Q *ptr; |
| 850 | |
| 851 | private: |
| 852 | }; |
| 853 | #else |
| 854 | T t; |
| 855 | // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 856 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 857 | #endif |
| 858 | } // namespace StructWithForwardDeclarationNoDefinition |
| 859 | |
Richard Trieu | fe56405 | 2017-04-20 02:53:53 +0000 | [diff] [blame^] | 860 | namespace LateParsedDefaultArgument { |
| 861 | #if defined(FIRST) |
| 862 | template <typename T> |
| 863 | struct S { |
| 864 | struct R { |
| 865 | void foo(T x = 0) {} |
| 866 | }; |
| 867 | }; |
| 868 | #elif defined(SECOND) |
| 869 | #else |
| 870 | void run() { |
| 871 | S<int>::R().foo(); |
| 872 | } |
| 873 | #endif |
| 874 | } |
| 875 | |
| 876 | namespace LateParsedDefaultArgument { |
| 877 | #if defined(FIRST) |
| 878 | template <typename alpha> struct Bravo { |
| 879 | void charlie(bool delta = false) {} |
| 880 | }; |
| 881 | typedef Bravo<char> echo; |
| 882 | echo foxtrot; |
| 883 | |
| 884 | Bravo<char> golf; |
| 885 | #elif defined(SECOND) |
| 886 | #else |
| 887 | #endif |
| 888 | } |
| 889 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 890 | // Keep macros contained to one file. |
| 891 | #ifdef FIRST |
| 892 | #undef FIRST |
| 893 | #endif |
| 894 | #ifdef SECOND |
| 895 | #undef SECOND |
| 896 | #endif |