blob: f6127adcbd8952007d77e5e979f26c7ad53c8e19 [file] [log] [blame]
Douglas Gregor97eec242011-09-15 22:00:41 +00001// RUN: rm -rf %t
Bruno Cardoso Lopes297299192017-12-22 02:53:30 +00002// RUN: %clang_cc1 -Wauto-import -Wno-private-module -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify -DERRORS
3// RUN: %clang_cc1 -Wauto-import -Wno-private-module -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify
4// RUN: %clang_cc1 -Wauto-import -Wno-private-module -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs -xobjective-c++ %s -verify
Richard Smithe156254d2013-08-20 20:35:18 +00005//
6// Test both with and without the declarations that refer to unimported
7// entities. For error recovery, those cases implicitly trigger an import.
Douglas Gregor97eec242011-09-15 22:00:41 +00008
Douglas Gregor41e115a2011-11-30 18:02:36 +00009#include <DependsOnModule/DependsOnModule.h> // expected-warning{{treating #include as an import of module 'DependsOnModule'}}
Douglas Gregor97eec242011-09-15 22:00:41 +000010
11#ifdef MODULE_H_MACRO
12# error MODULE_H_MACRO should have been hidden
13#endif
14
15#ifdef DEPENDS_ON_MODULE
16# error DEPENDS_ON_MODULE should have been hidden
17#endif
Douglas Gregorcf68c582011-12-01 22:20:10 +000018
Richard Smithe156254d2013-08-20 20:35:18 +000019#ifdef ERRORS
20Module *mod; // expected-error{{declaration of 'Module' must be imported from module 'Module' before it is required}}
21// expected-note@Inputs/Module.framework/Headers/Module.h:15 {{previous}}
22#else
Douglas Gregord8bd7532011-12-05 17:40:25 +000023#import <AlsoDependsOnModule/AlsoDependsOnModule.h> // expected-warning{{treating #import as an import of module 'AlsoDependsOnModule'}}
Richard Smithe156254d2013-08-20 20:35:18 +000024#endif
Douglas Gregord8bd7532011-12-05 17:40:25 +000025Module *mod2;
26
Douglas Gregore5626c42011-12-06 17:15:11 +000027int getDependsOther() { return depends_on_module_other; }
Douglas Gregor356f3d42011-12-06 17:31:28 +000028
29void testSubframeworkOther() {
Richard Smithe156254d2013-08-20 20:35:18 +000030#ifdef ERRORS
31 double *sfo1 = sub_framework_other; // expected-error{{declaration of 'sub_framework_other' must be imported from module 'DependsOnModule.SubFramework.Other'}}
32 // expected-note@Inputs/DependsOnModule.framework/Frameworks/SubFramework.framework/Headers/Other.h:15 {{previous}}
33#endif
Douglas Gregor356f3d42011-12-06 17:31:28 +000034}
35
Douglas Gregor70331272011-12-09 02:04:43 +000036// Test umbrella-less submodule includes
37#include <NoUmbrella/A.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.A'}}
38int getNoUmbrellaA() { return no_umbrella_A; }
39
Douglas Gregorc1aaf8c2011-12-12 19:13:53 +000040// Test umbrella-less submodule includes
41#include <NoUmbrella/SubDir/C.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.SubDir.C'}}
42int getNoUmbrellaC() { return no_umbrella_C; }
43
Richard Smithe156254d2013-08-20 20:35:18 +000044#ifndef ERRORS
Douglas Gregor356f3d42011-12-06 17:31:28 +000045// Test header cross-subframework include pattern.
Douglas Gregordd005f62011-12-06 17:34:58 +000046#include <DependsOnModule/../Frameworks/SubFramework.framework/Headers/Other.h> // expected-warning{{treating #include as an import of module 'DependsOnModule.SubFramework.Other'}}
Richard Smithe156254d2013-08-20 20:35:18 +000047#endif
Douglas Gregor356f3d42011-12-06 17:31:28 +000048
49void testSubframeworkOtherAgain() {
50 double *sfo1 = sub_framework_other;
51}
Douglas Gregore89dbc12011-12-06 19:39:29 +000052
53void testModuleSubFramework() {
54 char *msf = module_subframework;
55}
56
57#include <Module/../Frameworks/SubFramework.framework/Headers/SubFramework.h> // expected-warning{{treating #include as an import of module 'Module.SubFramework'}}
58
59void testModuleSubFrameworkAgain() {
60 char *msf = module_subframework;
61}
Douglas Gregore7ab3662011-12-07 02:23:45 +000062
63// Test inclusion of private headers.
64#include <DependsOnModule/DependsOnModulePrivate.h> // expected-warning{{treating #include as an import of module 'DependsOnModule.Private.DependsOnModule'}}
Douglas Gregor80306772011-12-07 21:25:07 +000065
66int getDependsOnModulePrivate() { return depends_on_module_private; }
Douglas Gregor9458f822011-12-07 22:05:21 +000067
Douglas Gregor09a22f02012-01-13 16:54:27 +000068#include <Module/ModulePrivate.h> // includes the header
Douglas Gregor9458f822011-12-07 22:05:21 +000069
70int getModulePrivate() { return module_private; }
Douglas Gregor70331272011-12-09 02:04:43 +000071
72#include <NoUmbrella/A_Private.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.Private.A_Private'}}
73int getNoUmbrellaAPrivate() { return no_umbrella_A_private; }
74
Richard Smithe156254d2013-08-20 20:35:18 +000075int getNoUmbrellaBPrivateFail() { return no_umbrella_B_private; } // expected-error{{declaration of 'no_umbrella_B_private' must be imported from module 'NoUmbrella.Private.B_Private'}}
76// expected-note@Inputs/NoUmbrella.framework/PrivateHeaders/B_Private.h:1 {{previous}}
Douglas Gregor98a52db2011-12-20 00:28:52 +000077
78// Test inclusion of headers that are under an umbrella directory but
79// not actually part of the module.
80#include <Module/NotInModule.h> // expected-warning{{treating #include as an import of module 'Module.NotInModule'}} \
81 // expected-warning{{missing submodule 'Module.NotInModule'}}
82
83int getNotInModule() {
84 return not_in_module;
85}
Richard Smithce587f52013-11-15 04:24:58 +000086
Serge Pavlovc4e04a22015-09-19 05:32:57 +000087void includeNotAtTopLevel() { // expected-note {{function 'includeNotAtTopLevel' begins here}}
88 #include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} \
Richard Smith752ada82015-11-17 23:32:01 +000089 expected-error {{redundant #include of module 'NoUmbrella.A' appears within function 'includeNotAtTopLevel'}}
Serge Pavlovc4e04a22015-09-19 05:32:57 +000090}
Richard Smith752ada82015-11-17 23:32:01 +000091
92#ifdef __cplusplus
93namespace NS { // expected-note {{begins here}}
94#include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} \
95 expected-error {{redundant #include of module 'NoUmbrella.A' appears within namespace 'NS'}}
96}
97extern "C" { // expected-note {{begins here}}
98#include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} \
99 expected-error {{import of C++ module 'NoUmbrella.A' appears within extern "C"}}
100}
101#endif