Douglas Gregor | 97eec24 | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -F %S/Inputs %s -verify -DERRORS |
Douglas Gregor | 35b04d6 | 2013-02-07 19:01:24 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -F %S/Inputs %s -verify |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 4 | // |
| 5 | // Test both with and without the declarations that refer to unimported |
| 6 | // entities. For error recovery, those cases implicitly trigger an import. |
Douglas Gregor | 97eec24 | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 7 | |
Douglas Gregor | 41e115a | 2011-11-30 18:02:36 +0000 | [diff] [blame] | 8 | #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] | 9 | |
| 10 | #ifdef MODULE_H_MACRO |
| 11 | # error MODULE_H_MACRO should have been hidden |
| 12 | #endif |
| 13 | |
| 14 | #ifdef DEPENDS_ON_MODULE |
| 15 | # error DEPENDS_ON_MODULE should have been hidden |
| 16 | #endif |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 17 | |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 18 | #ifdef ERRORS |
| 19 | Module *mod; // expected-error{{declaration of 'Module' must be imported from module 'Module' before it is required}} |
| 20 | // expected-note@Inputs/Module.framework/Headers/Module.h:15 {{previous}} |
| 21 | #else |
Douglas Gregor | d8bd753 | 2011-12-05 17:40:25 +0000 | [diff] [blame] | 22 | #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] | 23 | #endif |
Douglas Gregor | d8bd753 | 2011-12-05 17:40:25 +0000 | [diff] [blame] | 24 | Module *mod2; |
| 25 | |
Douglas Gregor | e5626c4 | 2011-12-06 17:15:11 +0000 | [diff] [blame] | 26 | int getDependsOther() { return depends_on_module_other; } |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 27 | |
| 28 | void testSubframeworkOther() { |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 29 | #ifdef ERRORS |
| 30 | double *sfo1 = sub_framework_other; // expected-error{{declaration of 'sub_framework_other' must be imported from module 'DependsOnModule.SubFramework.Other'}} |
| 31 | // expected-note@Inputs/DependsOnModule.framework/Frameworks/SubFramework.framework/Headers/Other.h:15 {{previous}} |
| 32 | #endif |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Douglas Gregor | 7033127 | 2011-12-09 02:04:43 +0000 | [diff] [blame] | 35 | // Test umbrella-less submodule includes |
| 36 | #include <NoUmbrella/A.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.A'}} |
| 37 | int getNoUmbrellaA() { return no_umbrella_A; } |
| 38 | |
Douglas Gregor | c1aaf8c | 2011-12-12 19:13:53 +0000 | [diff] [blame] | 39 | // Test umbrella-less submodule includes |
| 40 | #include <NoUmbrella/SubDir/C.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.SubDir.C'}} |
| 41 | int getNoUmbrellaC() { return no_umbrella_C; } |
| 42 | |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 43 | #ifndef ERRORS |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 44 | // Test header cross-subframework include pattern. |
Douglas Gregor | dd005f6 | 2011-12-06 17:34:58 +0000 | [diff] [blame] | 45 | #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] | 46 | #endif |
Douglas Gregor | 356f3d4 | 2011-12-06 17:31:28 +0000 | [diff] [blame] | 47 | |
| 48 | void testSubframeworkOtherAgain() { |
| 49 | double *sfo1 = sub_framework_other; |
| 50 | } |
Douglas Gregor | e89dbc1 | 2011-12-06 19:39:29 +0000 | [diff] [blame] | 51 | |
| 52 | void testModuleSubFramework() { |
| 53 | char *msf = module_subframework; |
| 54 | } |
| 55 | |
| 56 | #include <Module/../Frameworks/SubFramework.framework/Headers/SubFramework.h> // expected-warning{{treating #include as an import of module 'Module.SubFramework'}} |
| 57 | |
| 58 | void testModuleSubFrameworkAgain() { |
| 59 | char *msf = module_subframework; |
| 60 | } |
Douglas Gregor | e7ab366 | 2011-12-07 02:23:45 +0000 | [diff] [blame] | 61 | |
| 62 | // Test inclusion of private headers. |
| 63 | #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] | 64 | |
| 65 | int getDependsOnModulePrivate() { return depends_on_module_private; } |
Douglas Gregor | 9458f82 | 2011-12-07 22:05:21 +0000 | [diff] [blame] | 66 | |
Douglas Gregor | 09a22f0 | 2012-01-13 16:54:27 +0000 | [diff] [blame] | 67 | #include <Module/ModulePrivate.h> // includes the header |
Douglas Gregor | 9458f82 | 2011-12-07 22:05:21 +0000 | [diff] [blame] | 68 | |
| 69 | int getModulePrivate() { return module_private; } |
Douglas Gregor | 7033127 | 2011-12-09 02:04:43 +0000 | [diff] [blame] | 70 | |
| 71 | #include <NoUmbrella/A_Private.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.Private.A_Private'}} |
| 72 | int getNoUmbrellaAPrivate() { return no_umbrella_A_private; } |
| 73 | |
Richard Smith | e156254d | 2013-08-20 20:35:18 +0000 | [diff] [blame] | 74 | int getNoUmbrellaBPrivateFail() { return no_umbrella_B_private; } // expected-error{{declaration of 'no_umbrella_B_private' must be imported from module 'NoUmbrella.Private.B_Private'}} |
| 75 | // expected-note@Inputs/NoUmbrella.framework/PrivateHeaders/B_Private.h:1 {{previous}} |
Douglas Gregor | 98a52db | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 76 | |
| 77 | // Test inclusion of headers that are under an umbrella directory but |
| 78 | // not actually part of the module. |
| 79 | #include <Module/NotInModule.h> // expected-warning{{treating #include as an import of module 'Module.NotInModule'}} \ |
| 80 | // expected-warning{{missing submodule 'Module.NotInModule'}} |
| 81 | |
| 82 | int getNotInModule() { |
| 83 | return not_in_module; |
| 84 | } |