Douglas Gregor | 97eec24 | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Bruno Cardoso Lopes | 29729919 | 2017-12-22 02:53:30 +0000 | [diff] [blame] | 2 | // 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 Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 5 | // |
| 6 | // Test both with and without the declarations that refer to unimported |
| 7 | // entities. For error recovery, those cases implicitly trigger an import. |
Douglas Gregor | 97eec24 | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 8 | |
Douglas Gregor | 41e115a | 2011-11-30 18:02:36 +0000 | [diff] [blame] | 9 | #include <DependsOnModule/DependsOnModule.h> // expected-warning{{treating #include as an import of module 'DependsOnModule'}} |
Douglas Gregor | 97eec24 | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 10 | |
| 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 Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 18 | |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 19 | #ifdef ERRORS |
| 20 | Module *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 Gregor | d8bd753 | 2011-12-05 17:40:25 +0000 | [diff] [blame] | 23 | #import <AlsoDependsOnModule/AlsoDependsOnModule.h> // expected-warning{{treating #import as an import of module 'AlsoDependsOnModule'}} |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 24 | #endif |
Douglas Gregor | d8bd753 | 2011-12-05 17:40:25 +0000 | [diff] [blame] | 25 | Module *mod2; |
| 26 | |
Douglas Gregor | e5626c4 | 2011-12-06 17:15:11 +0000 | [diff] [blame] | 27 | int getDependsOther() { return depends_on_module_other; } |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 28 | |
| 29 | void testSubframeworkOther() { |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 30 | #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 Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Douglas Gregor | 7033127 | 2011-12-09 02:04:43 +0000 | [diff] [blame] | 36 | // Test umbrella-less submodule includes |
| 37 | #include <NoUmbrella/A.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.A'}} |
| 38 | int getNoUmbrellaA() { return no_umbrella_A; } |
| 39 | |
Douglas Gregor | c1aaf8c | 2011-12-12 19:13:53 +0000 | [diff] [blame] | 40 | // Test umbrella-less submodule includes |
| 41 | #include <NoUmbrella/SubDir/C.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.SubDir.C'}} |
| 42 | int getNoUmbrellaC() { return no_umbrella_C; } |
| 43 | |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 44 | #ifndef ERRORS |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 45 | // Test header cross-subframework include pattern. |
Douglas Gregor | dd005f6 | 2011-12-06 17:34:58 +0000 | [diff] [blame] | 46 | #include <DependsOnModule/../Frameworks/SubFramework.framework/Headers/Other.h> // expected-warning{{treating #include as an import of module 'DependsOnModule.SubFramework.Other'}} |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 47 | #endif |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 48 | |
| 49 | void testSubframeworkOtherAgain() { |
| 50 | double *sfo1 = sub_framework_other; |
| 51 | } |
Douglas Gregor | e89dbc1 | 2011-12-06 19:39:29 +0000 | [diff] [blame] | 52 | |
| 53 | void 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 | |
| 59 | void testModuleSubFrameworkAgain() { |
| 60 | char *msf = module_subframework; |
| 61 | } |
Douglas Gregor | e7ab366 | 2011-12-07 02:23:45 +0000 | [diff] [blame] | 62 | |
| 63 | // Test inclusion of private headers. |
| 64 | #include <DependsOnModule/DependsOnModulePrivate.h> // expected-warning{{treating #include as an import of module 'DependsOnModule.Private.DependsOnModule'}} |
Douglas Gregor | 8030677 | 2011-12-07 21:25:07 +0000 | [diff] [blame] | 65 | |
| 66 | int getDependsOnModulePrivate() { return depends_on_module_private; } |
Douglas Gregor | 9458f82 | 2011-12-07 22:05:21 +0000 | [diff] [blame] | 67 | |
Douglas Gregor | 09a22f0 | 2012-01-13 16:54:27 +0000 | [diff] [blame] | 68 | #include <Module/ModulePrivate.h> // includes the header |
Douglas Gregor | 9458f82 | 2011-12-07 22:05:21 +0000 | [diff] [blame] | 69 | |
| 70 | int getModulePrivate() { return module_private; } |
Douglas Gregor | 7033127 | 2011-12-09 02:04:43 +0000 | [diff] [blame] | 71 | |
| 72 | #include <NoUmbrella/A_Private.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.Private.A_Private'}} |
| 73 | int getNoUmbrellaAPrivate() { return no_umbrella_A_private; } |
| 74 | |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 75 | int 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 Gregor | 98a52db | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 77 | |
| 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 | |
| 83 | int getNotInModule() { |
| 84 | return not_in_module; |
| 85 | } |
Richard Smith | ce587f5 | 2013-11-15 04:24:58 +0000 | [diff] [blame] | 86 | |
Serge Pavlov | c4e04a2 | 2015-09-19 05:32:57 +0000 | [diff] [blame] | 87 | void includeNotAtTopLevel() { // expected-note {{function 'includeNotAtTopLevel' begins here}} |
| 88 | #include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} \ |
Richard Smith | 752ada8 | 2015-11-17 23:32:01 +0000 | [diff] [blame] | 89 | expected-error {{redundant #include of module 'NoUmbrella.A' appears within function 'includeNotAtTopLevel'}} |
Serge Pavlov | c4e04a2 | 2015-09-19 05:32:57 +0000 | [diff] [blame] | 90 | } |
Richard Smith | 752ada8 | 2015-11-17 23:32:01 +0000 | [diff] [blame] | 91 | |
| 92 | #ifdef __cplusplus |
| 93 | namespace 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 | } |
| 97 | extern "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 |