Richard Trieu | 22ddc28 | 2018-09-04 22:53:19 +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 | // Test that each header can compile |
| 16 | // RUN: %clang_cc1 -fsyntax-only -x c++ -std=gnu++11 %t/Inputs/first.h |
| 17 | // RUN: %clang_cc1 -fsyntax-only -x c++ -std=gnu++11 %t/Inputs/second.h |
| 18 | |
| 19 | // Build module map file |
| 20 | // RUN: echo "module FirstModule {" >> %t/Inputs/module.map |
| 21 | // RUN: echo " header \"first.h\"" >> %t/Inputs/module.map |
| 22 | // RUN: echo "}" >> %t/Inputs/module.map |
| 23 | // RUN: echo "module SecondModule {" >> %t/Inputs/module.map |
| 24 | // RUN: echo " header \"second.h\"" >> %t/Inputs/module.map |
| 25 | // RUN: echo "}" >> %t/Inputs/module.map |
| 26 | |
| 27 | // Run test |
Richard Trieu | 0b9234b9 | 2018-09-05 22:14:46 +0000 | [diff] [blame] | 28 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=gnu++11 |
Richard Trieu | 22ddc28 | 2018-09-04 22:53:19 +0000 | [diff] [blame] | 29 | |
| 30 | #if !defined(FIRST) && !defined(SECOND) |
| 31 | #include "first.h" |
| 32 | #include "second.h" |
| 33 | #endif |
| 34 | |
| 35 | namespace Types { |
| 36 | namespace TypeOfExpr { |
| 37 | #if defined(FIRST) |
| 38 | struct Invalid1 { |
| 39 | typeof(1 + 2) x; |
| 40 | }; |
| 41 | double global; |
| 42 | struct Invalid2 { |
| 43 | typeof(global) x; |
| 44 | }; |
| 45 | struct Valid { |
| 46 | typeof(3) x; |
| 47 | typeof(x) y; |
| 48 | typeof(Valid*) self; |
| 49 | }; |
| 50 | #elif defined(SECOND) |
| 51 | struct Invalid1 { |
| 52 | typeof(3) x; |
| 53 | }; |
| 54 | int global; |
| 55 | struct Invalid2 { |
| 56 | typeof(global) x; |
| 57 | }; |
| 58 | struct Valid { |
| 59 | typeof(3) x; |
| 60 | typeof(x) y; |
| 61 | typeof(Valid*) self; |
| 62 | }; |
| 63 | #else |
| 64 | Invalid1 i1; |
| 65 | // expected-error@first.h:* {{'Types::TypeOfExpr::Invalid1' has different definitions in different modules; first difference is definition in module 'FirstModule' found field 'x' with type 'typeof (1 + 2)' (aka 'int')}} |
| 66 | // expected-note@second.h:* {{but in 'SecondModule' found field 'x' with type 'typeof (3)' (aka 'int')}} |
| 67 | Invalid2 i2; |
| 68 | // expected-error@second.h:* {{'Types::TypeOfExpr::Invalid2::x' from module 'SecondModule' is not present in definition of 'Types::TypeOfExpr::Invalid2' in module 'FirstModule'}} |
| 69 | // expected-note@first.h:* {{declaration of 'x' does not match}} |
| 70 | Valid v; |
| 71 | #endif |
| 72 | } // namespace TypeOfExpr |
| 73 | |
| 74 | namespace TypeOf { |
| 75 | #if defined(FIRST) |
| 76 | struct Invalid1 { |
| 77 | typeof(int) x; |
| 78 | }; |
| 79 | struct Invalid2 { |
| 80 | typeof(int) x; |
| 81 | }; |
| 82 | using T = int; |
| 83 | struct Invalid3 { |
| 84 | typeof(T) x; |
| 85 | }; |
| 86 | struct Valid { |
| 87 | typeof(int) x; |
| 88 | using T = typeof(double); |
| 89 | typeof(T) y; |
| 90 | }; |
| 91 | #elif defined(SECOND) |
| 92 | struct Invalid1 { |
| 93 | typeof(double) x; |
| 94 | }; |
| 95 | using I = int; |
| 96 | struct Invalid2 { |
| 97 | typeof(I) x; |
| 98 | }; |
| 99 | using T = short; |
| 100 | struct Invalid3 { |
| 101 | typeof(T) x; |
| 102 | }; |
| 103 | struct Valid { |
| 104 | typeof(int) x; |
| 105 | using T = typeof(double); |
| 106 | typeof(T) y; |
| 107 | }; |
| 108 | #else |
| 109 | Invalid1 i1; |
| 110 | // expected-error@second.h:* {{'Types::TypeOf::Invalid1::x' from module 'SecondModule' is not present in definition of 'Types::TypeOf::Invalid1' in module 'FirstModule'}} |
| 111 | // expected-note@first.h:* {{declaration of 'x' does not match}} |
| 112 | Invalid2 i2; |
| 113 | // expected-error@first.h:* {{'Types::TypeOf::Invalid2' has different definitions in different modules; first difference is definition in module 'FirstModule' found field 'x' with type 'typeof(int)' (aka 'int')}} |
| 114 | // expected-note@second.h:* {{but in 'SecondModule' found field 'x' with type 'typeof(Types::TypeOf::I)' (aka 'int')}} |
| 115 | Invalid3 i3; |
| 116 | // expected-error@second.h:* {{'Types::TypeOf::Invalid3::x' from module 'SecondModule' is not present in definition of 'Types::TypeOf::Invalid3' in module 'FirstModule'}} |
| 117 | // expected-note@first.h:* {{declaration of 'x' does not match}} |
| 118 | Valid v; |
| 119 | #endif |
| 120 | } // namespace TypeOf |
| 121 | } // namespace Types |
| 122 | |
| 123 | // Keep macros contained to one file. |
| 124 | #ifdef FIRST |
| 125 | #undef FIRST |
| 126 | #endif |
| 127 | |
| 128 | #ifdef SECOND |
| 129 | #undef SECOND |
| 130 | #endif |