122 lines · cpp
1// Clear and create directories2// RUN: rm -rf %t3// RUN: mkdir %t4// RUN: mkdir %t/cache5// RUN: mkdir %t/Inputs6 7// Build first header file8// RUN: echo "#define FIRST" >> %t/Inputs/first.h9// RUN: cat %s >> %t/Inputs/first.h10 11// Build second header file12// RUN: echo "#define SECOND" >> %t/Inputs/second.h13// RUN: cat %s >> %t/Inputs/second.h14 15// Test that each header can compile16// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++11 -fblocks %t/Inputs/first.h17// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++11 -fblocks %t/Inputs/second.h18 19// Build module map file20// RUN: echo "module FirstModule {" >> %t/Inputs/module.modulemap21// RUN: echo " header \"first.h\"" >> %t/Inputs/module.modulemap22// RUN: echo "}" >> %t/Inputs/module.modulemap23// RUN: echo "module SecondModule {" >> %t/Inputs/module.modulemap24// RUN: echo " header \"second.h\"" >> %t/Inputs/module.modulemap25// RUN: echo "}" >> %t/Inputs/module.modulemap26 27// Run test28// RUN: %clang_cc1 -fmodules -fimplicit-module-maps \29// RUN: -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs \30// RUN: -verify %s -std=c++11 -fblocks31 32#if !defined(FIRST) && !defined(SECOND)33#include "first.h"34#include "second.h"35#endif36 37// Used for testing38#if defined(FIRST)39#define ACCESS public:40#elif defined(SECOND)41#define ACCESS private:42#endif43 44// TODO: S1 and S2 should generate errors.45namespace Blocks {46#if defined(FIRST)47struct S1 {48 void (^block)(int x) = ^(int x) { };49};50#elif defined(SECOND)51struct S1 {52 void (^block)(int x) = ^(int y) { };53};54#else55S1 s1;56#endif57 58#if defined(FIRST)59struct S2 {60 int (^block)(int x) = ^(int x) { return x + 1; };61};62#elif defined(SECOND)63struct S2 {64 int (^block)(int x) = ^(int x) { return x; };65};66#else67S2 s2;68#endif69 70#if defined(FIRST)71struct S3 {72 void run(int (^block)(int x));73};74#elif defined(SECOND)75struct S3 {76 void run(int (^block)(int x, int y));77};78#else79S3 s3;80// expected-error@first.h:* {{'Blocks::S3::run' from module 'FirstModule' is not present in definition of 'Blocks::S3' in module 'SecondModule'}}81// expected-note@second.h:* {{declaration of 'run' does not match}}82#endif83 84#define DECLS \85 int (^block)(int x) = ^(int x) { return x + x; }; \86 void run(int (^block)(int x, int y));87 88#if defined(FIRST) || defined(SECOND)89struct Valid1 {90 DECLS91};92#else93Valid1 v1;94#endif95 96#if defined(FIRST) || defined(SECOND)97struct Invalid1 {98 DECLS99 ACCESS100};101#else102Invalid1 i1;103// expected-error@second.h:* {{'Blocks::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}104// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}105#endif106 107#undef DECLS108}109 110// Keep macros contained to one file.111#ifdef FIRST112#undef FIRST113#endif114 115#ifdef SECOND116#undef SECOND117#endif118 119#ifdef ACCESS120#undef ACCESS121#endif122