// Clear and create directories // RUN: rm -rf %t // RUN: mkdir %t // RUN: mkdir %t/cache // RUN: mkdir %t/Inputs // Build first header file // RUN: echo "#define FIRST" >> %t/Inputs/first.h // RUN: cat %s >> %t/Inputs/first.h // Build second header file // RUN: echo "#define SECOND" >> %t/Inputs/second.h // RUN: cat %s >> %t/Inputs/second.h // Build module map file // RUN: echo "module first {" >> %t/Inputs/module.map // RUN: echo " header \"first.h\"" >> %t/Inputs/module.map // RUN: echo "}" >> %t/Inputs/module.map // RUN: echo "module second {" >> %t/Inputs/module.map // RUN: echo " header \"second.h\"" >> %t/Inputs/module.map // RUN: echo "}" >> %t/Inputs/module.map // Run test // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++11 #if !defined(FIRST) && !defined(SECOND) #include "first.h" #include "second.h" #endif #if defined(FIRST) struct S1 { public: }; #elif defined(SECOND) struct S1 { private: }; #else S1 s1; // expected-error@first.h:* {{'S1' has different definitions in different modules; first difference is definition in module 'first' found public access specifier}} // expected-note@second.h:* {{but in 'second' found private access specifier}} #endif #if defined(FIRST) struct S2Friend2 {}; struct S2 { friend S2Friend2; }; #elif defined(SECOND) struct S2Friend1 {}; struct S2 { friend S2Friend1; }; #else S2 s2; // expected-error@first.h:* {{'S2' has different definitions in different modules; first difference is definition in module 'first' found friend 'S2Friend2'}} // expected-note@second.h:* {{but in 'second' found other friend 'S2Friend1'}} #endif #if defined(FIRST) template struct S3Template {}; struct S3 { friend S3Template; }; #elif defined(SECOND) template struct S3Template {}; struct S3 { friend S3Template; }; #else S3 s3; // expected-error@first.h:* {{'S3' has different definitions in different modules; first difference is definition in module 'first' found friend 'S3Template'}} // expected-note@second.h:* {{but in 'second' found other friend 'S3Template'}} #endif #if defined(FIRST) struct S4 { static_assert(1 == 1, "First"); }; #elif defined(SECOND) struct S4 { static_assert(1 == 1, "Second"); }; #else S4 s4; // expected-error@first.h:* {{'S4' has different definitions in different modules; first difference is definition in module 'first' found static assert with message}} // expected-note@second.h:* {{but in 'second' found static assert with different message}} #endif #if defined(FIRST) struct S5 { static_assert(1 == 1, "Message"); }; #elif defined(SECOND) struct S5 { static_assert(2 == 2, "Message"); }; #else S5 s5; // expected-error@first.h:* {{'S5' has different definitions in different modules; first difference is definition in module 'first' found static assert with condition}} // expected-note@second.h:* {{but in 'second' found static assert with different condition}} #endif #if defined(FIRST) struct S6 { int First(); }; #elif defined(SECOND) struct S6 { int Second(); }; #else S6 s6; // expected-error@second.h:* {{'S6::Second' from module 'second' is not present in definition of 'S6' in module 'first'}} // expected-note@first.h:* {{definition has no member 'Second'}} #endif #if defined(FIRST) struct S7 { double foo(); }; #elif defined(SECOND) struct S7 { int foo(); }; #else S7 s7; // expected-error@second.h:* {{'S7::foo' from module 'second' is not present in definition of 'S7' in module 'first'}} // expected-note@first.h:* {{declaration of 'foo' does not match}} #endif #if defined(FIRST) struct S8 { void foo(); }; #elif defined(SECOND) struct S8 { void foo() {} }; #else S8 s8; // expected-error@first.h:* {{'S8' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S9 { void foo() { int y = 5; } }; #elif defined(SECOND) struct S9 { void foo() { int x = 5; } }; #else S9 s9; // expected-error@first.h:* {{'S9' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S10 { struct { int x; } a; }; #elif defined(SECOND) struct S10 { struct { int x; int y; } a; }; #else S10 s10; // expected-error-re@second.h:* {{'S10::(anonymous struct)::y' from module 'second' is not present in definition of 'S10::(anonymous struct at {{.*}}first.h:{{[0-9]*}}:{{[0-9]*}})' in module 'first'}} // expected-note@first.h:* {{definition has no member 'y'}} // expected-error@first.h:* {{'S10' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S11 { void foo() { int y = sizeof(int); } }; #elif defined(SECOND) struct S11 { void foo() { int y = sizeof(double); } }; #else S11 s11; // expected-error@first.h:* {{'S11' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S12 { int x = sizeof(x); int y = sizeof(x); }; #elif defined(SECOND) struct S12 { int x = sizeof(x); int y = sizeof(y); }; #else S12 s12; // expected-error@first.h:* {{'S12' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S13 { template void foo(); }; #elif defined(SECOND) struct S13 { template void foo(); }; #else S13 s13; // expected-error@first.h:* {{'S13' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S14 { template void foo(); }; #elif defined(SECOND) struct S14 { template void foo(); }; #else S14 s14; // expected-error@second.h:* {{'S14::foo' from module 'second' is not present in definition of 'S14' in module 'first'}} // expected-note@first.h:* {{declaration of 'foo' does not match}} #endif #if defined(FIRST) template struct S15 : T { void foo() { int x = __builtin_offsetof(T, first); } }; #elif defined(SECOND) template struct S15 : T { void foo() { int x = __builtin_offsetof(T, second); } }; #else template void Test15() { S15 s15; // expected-error@first.h:* {{'S15' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} } #endif #if defined(FIRST) struct S16 { template class Y> void foo() { Y<> y; } }; #elif defined(SECOND) struct S16 { template class Y> void foo() { Y<> y; } }; #else void TestS16() { S16 s16; } // expected-error@first.h:* {{'S16' has different definitions in different modules; definition in module 'first' is here}} // expected-note@second.h:* {{definition in module 'second' is here}} #endif #if defined(FIRST) struct S17 { template