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; |
| 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 'B' (aka 'int')}} |
| 187 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}} |
| 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'}} |
| 191 | // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}} |
| 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 | |
| 433 | // Interesting cases that should not cause errors. struct S should not error |
| 434 | // while struct T should error at the access specifier mismatch at the end. |
| 435 | namespace AllDecls { |
| 436 | #if defined(FIRST) |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 437 | typedef int INT; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 438 | struct S { |
| 439 | public: |
| 440 | private: |
| 441 | protected: |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 442 | |
| 443 | static_assert(1 == 1, "Message"); |
| 444 | static_assert(2 == 2); |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 445 | |
| 446 | int x; |
| 447 | double y; |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 448 | |
| 449 | INT z; |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 450 | |
| 451 | unsigned a : 1; |
| 452 | unsigned b : 2*2 + 5/2; |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 453 | |
| 454 | mutable int c = sizeof(x + y); |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 455 | |
| 456 | void method() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 457 | static void static_method() {} |
| 458 | virtual void virtual_method() {} |
| 459 | virtual void pure_virtual_method() = 0; |
| 460 | inline void inline_method() {} |
| 461 | void volatile_method() volatile {} |
| 462 | void const_method() const {} |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 463 | }; |
| 464 | #elif defined(SECOND) |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 465 | typedef int INT; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 466 | struct S { |
| 467 | public: |
| 468 | private: |
| 469 | protected: |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 470 | |
| 471 | static_assert(1 == 1, "Message"); |
| 472 | static_assert(2 == 2); |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 473 | |
| 474 | int x; |
| 475 | double y; |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 476 | |
| 477 | INT z; |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 478 | |
| 479 | unsigned a : 1; |
| 480 | unsigned b : 2 * 2 + 5 / 2; |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 481 | |
| 482 | mutable int c = sizeof(x + y); |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 483 | |
| 484 | void method() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 485 | static void static_method() {} |
| 486 | virtual void virtual_method() {} |
| 487 | virtual void pure_virtual_method() = 0; |
| 488 | inline void inline_method() {} |
| 489 | void volatile_method() volatile {} |
| 490 | void const_method() const {} |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 491 | }; |
| 492 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 493 | S *s; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 494 | #endif |
| 495 | |
| 496 | #if defined(FIRST) |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 497 | typedef int INT; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 498 | struct T { |
| 499 | public: |
| 500 | private: |
| 501 | protected: |
| 502 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 503 | static_assert(1 == 1, "Message"); |
| 504 | static_assert(2 == 2); |
| 505 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 506 | int x; |
| 507 | double y; |
| 508 | |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 509 | INT z; |
| 510 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 511 | unsigned a : 1; |
| 512 | unsigned b : 2 * 2 + 5 / 2; |
| 513 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 514 | mutable int c = sizeof(x + y); |
| 515 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 516 | void method() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 517 | static void static_method() {} |
| 518 | virtual void virtual_method() {} |
| 519 | virtual void pure_virtual_method() = 0; |
| 520 | inline void inline_method() {} |
| 521 | void volatile_method() volatile {} |
| 522 | void const_method() const {} |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 523 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 524 | private: |
| 525 | }; |
| 526 | #elif defined(SECOND) |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 527 | typedef int INT; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 528 | struct T { |
| 529 | public: |
| 530 | private: |
| 531 | protected: |
| 532 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 533 | static_assert(1 == 1, "Message"); |
| 534 | static_assert(2 == 2); |
| 535 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 536 | int x; |
| 537 | double y; |
| 538 | |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 539 | INT z; |
| 540 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 541 | unsigned a : 1; |
| 542 | unsigned b : 2 * 2 + 5 / 2; |
| 543 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 544 | mutable int c = sizeof(x + y); |
| 545 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 546 | void method() {} |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 547 | static void static_method() {} |
| 548 | virtual void virtual_method() {} |
| 549 | virtual void pure_virtual_method() = 0; |
| 550 | inline void inline_method() {} |
| 551 | void volatile_method() volatile {} |
| 552 | void const_method() const {} |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 553 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 554 | public: |
| 555 | }; |
| 556 | #else |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 557 | T *t; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 558 | // expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 559 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 560 | #endif |
| 561 | } |
| 562 | |
| 563 | namespace FriendFunction { |
| 564 | #if defined(FIRST) |
| 565 | void F(int = 0); |
| 566 | struct S { friend void F(int); }; |
| 567 | #elif defined(SECOND) |
| 568 | void F(int); |
| 569 | struct S { friend void F(int); }; |
| 570 | #else |
| 571 | S s; |
| 572 | #endif |
| 573 | |
| 574 | #if defined(FIRST) |
| 575 | void G(int = 0); |
| 576 | struct T { |
| 577 | friend void G(int); |
| 578 | |
| 579 | private: |
| 580 | }; |
| 581 | #elif defined(SECOND) |
| 582 | void G(int); |
| 583 | struct T { |
| 584 | friend void G(int); |
| 585 | |
| 586 | public: |
| 587 | }; |
| 588 | #else |
| 589 | T t; |
| 590 | // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 591 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 592 | #endif |
| 593 | } // namespace FriendFunction |
| 594 | |
| 595 | namespace ImplicitDecl { |
| 596 | #if defined(FIRST) |
| 597 | struct S { }; |
| 598 | void S_Constructors() { |
| 599 | // Trigger creation of implicit contructors |
| 600 | S foo; |
| 601 | S bar = foo; |
| 602 | S baz(bar); |
| 603 | } |
| 604 | #elif defined(SECOND) |
| 605 | struct S { }; |
| 606 | #else |
| 607 | S s; |
| 608 | #endif |
| 609 | |
| 610 | #if defined(FIRST) |
| 611 | struct T { |
| 612 | private: |
| 613 | }; |
| 614 | void T_Constructors() { |
| 615 | // Trigger creation of implicit contructors |
| 616 | T foo; |
| 617 | T bar = foo; |
| 618 | T baz(bar); |
| 619 | } |
| 620 | #elif defined(SECOND) |
| 621 | struct T { |
| 622 | public: |
| 623 | }; |
| 624 | #else |
| 625 | T t; |
| 626 | // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}} |
| 627 | // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}} |
| 628 | #endif |
| 629 | |
| 630 | } // namespace ImplicitDelc |
| 631 | |
| 632 | namespace TemplatedClass { |
| 633 | #if defined(FIRST) |
| 634 | template <class> |
| 635 | struct S {}; |
| 636 | #elif defined(SECOND) |
| 637 | template <class> |
| 638 | struct S {}; |
| 639 | #else |
| 640 | S<int> s; |
| 641 | #endif |
| 642 | |
| 643 | #if defined(FIRST) |
| 644 | template <class> |
| 645 | struct T { |
| 646 | private: |
| 647 | }; |
| 648 | #elif defined(SECOND) |
| 649 | template <class> |
| 650 | struct T { |
| 651 | public: |
| 652 | }; |
| 653 | #else |
| 654 | T<int> t; |
| 655 | // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 656 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 657 | #endif |
| 658 | } // namespace TemplatedClass |
| 659 | |
| 660 | namespace TemplateClassWithField { |
| 661 | #if defined(FIRST) |
| 662 | template <class A> |
| 663 | struct S { |
| 664 | A a; |
| 665 | }; |
| 666 | #elif defined(SECOND) |
| 667 | template <class A> |
| 668 | struct S { |
| 669 | A a; |
| 670 | }; |
| 671 | #else |
| 672 | S<int> s; |
| 673 | #endif |
| 674 | |
| 675 | #if defined(FIRST) |
| 676 | template <class A> |
| 677 | struct T { |
| 678 | A a; |
| 679 | |
| 680 | private: |
| 681 | }; |
| 682 | #elif defined(SECOND) |
| 683 | template <class A> |
| 684 | struct T { |
| 685 | A a; |
| 686 | |
| 687 | public: |
| 688 | }; |
| 689 | #else |
| 690 | T<int> t; |
| 691 | // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}} |
| 692 | // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}} |
| 693 | #endif |
| 694 | } // namespace TemplateClassWithField |
| 695 | |
| 696 | namespace TemplateClassWithTemplateField { |
| 697 | #if defined(FIRST) |
| 698 | template <class A> |
| 699 | class WrapperS; |
| 700 | template <class A> |
| 701 | struct S { |
| 702 | WrapperS<A> a; |
| 703 | }; |
| 704 | #elif defined(SECOND) |
| 705 | template <class A> |
| 706 | class WrapperS; |
| 707 | template <class A> |
| 708 | struct S { |
| 709 | WrapperS<A> a; |
| 710 | }; |
| 711 | #else |
| 712 | template <class A> |
| 713 | class WrapperS{}; |
| 714 | S<int> s; |
| 715 | #endif |
| 716 | |
| 717 | #if defined(FIRST) |
| 718 | template <class A> |
| 719 | class WrapperT; |
| 720 | template <class A> |
| 721 | struct T { |
| 722 | WrapperT<A> a; |
| 723 | |
| 724 | public: |
| 725 | }; |
| 726 | #elif defined(SECOND) |
| 727 | template <class A> |
| 728 | class WrapperT; |
| 729 | template <class A> |
| 730 | struct T { |
| 731 | WrapperT<A> a; |
| 732 | |
| 733 | private: |
| 734 | }; |
| 735 | #else |
| 736 | template <class A> |
| 737 | class WrapperT{}; |
| 738 | T<int> t; |
| 739 | // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 740 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 741 | #endif |
| 742 | } // namespace TemplateClassWithTemplateField |
| 743 | |
| 744 | namespace EnumWithForwardDeclaration { |
| 745 | #if defined(FIRST) |
| 746 | enum E : int; |
| 747 | struct S { |
| 748 | void get(E) {} |
| 749 | }; |
| 750 | #elif defined(SECOND) |
| 751 | enum E : int { A, B }; |
| 752 | struct S { |
| 753 | void get(E) {} |
| 754 | }; |
| 755 | #else |
| 756 | S s; |
| 757 | #endif |
| 758 | |
| 759 | #if defined(FIRST) |
| 760 | struct T { |
| 761 | void get(E) {} |
| 762 | public: |
| 763 | }; |
| 764 | #elif defined(SECOND) |
| 765 | struct T { |
| 766 | void get(E) {} |
| 767 | private: |
| 768 | }; |
| 769 | #else |
| 770 | T t; |
| 771 | // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 772 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 773 | #endif |
| 774 | } // namespace EnumWithForwardDeclaration |
| 775 | |
| 776 | namespace StructWithForwardDeclaration { |
| 777 | #if defined(FIRST) |
| 778 | struct P {}; |
| 779 | struct S { |
| 780 | struct P *ptr; |
| 781 | }; |
| 782 | #elif defined(SECOND) |
| 783 | struct S { |
| 784 | struct P *ptr; |
| 785 | }; |
| 786 | #else |
| 787 | S s; |
| 788 | #endif |
| 789 | |
| 790 | #if defined(FIRST) |
| 791 | struct Q {}; |
| 792 | struct T { |
| 793 | struct Q *ptr; |
| 794 | public: |
| 795 | }; |
| 796 | #elif defined(SECOND) |
| 797 | struct T { |
| 798 | struct Q *ptr; |
| 799 | private: |
| 800 | }; |
| 801 | #else |
| 802 | T t; |
| 803 | // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 804 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 805 | #endif |
| 806 | } // namespace StructWithForwardDeclaration |
| 807 | |
| 808 | namespace StructWithForwardDeclarationNoDefinition { |
| 809 | #if defined(FIRST) |
| 810 | struct P; |
| 811 | struct S { |
| 812 | struct P *ptr; |
| 813 | }; |
| 814 | #elif defined(SECOND) |
| 815 | struct S { |
| 816 | struct P *ptr; |
| 817 | }; |
| 818 | #else |
| 819 | S s; |
| 820 | #endif |
| 821 | |
| 822 | #if defined(FIRST) |
| 823 | struct Q; |
| 824 | struct T { |
| 825 | struct Q *ptr; |
| 826 | |
| 827 | public: |
| 828 | }; |
| 829 | #elif defined(SECOND) |
| 830 | struct T { |
| 831 | struct Q *ptr; |
| 832 | |
| 833 | private: |
| 834 | }; |
| 835 | #else |
| 836 | T t; |
| 837 | // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}} |
| 838 | // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}} |
| 839 | #endif |
| 840 | } // namespace StructWithForwardDeclarationNoDefinition |
| 841 | |
| 842 | // Keep macros contained to one file. |
| 843 | #ifdef FIRST |
| 844 | #undef FIRST |
| 845 | #endif |
| 846 | #ifdef SECOND |
| 847 | #undef SECOND |
| 848 | #endif |