xref: /minix3/external/bsd/llvm/dist/clang/test/Modules/auto-module-import.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: rm -rf %t
2f4a2713aSLionel Sambuc// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -F %S/Inputs %s -verify -DERRORS
3f4a2713aSLionel Sambuc// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -F %S/Inputs %s -verify
4f4a2713aSLionel Sambuc//
5f4a2713aSLionel Sambuc// Test both with and without the declarations that refer to unimported
6f4a2713aSLionel Sambuc// entities. For error recovery, those cases implicitly trigger an import.
7f4a2713aSLionel Sambuc
8f4a2713aSLionel Sambuc#include <DependsOnModule/DependsOnModule.h> // expected-warning{{treating #include as an import of module 'DependsOnModule'}}
9f4a2713aSLionel Sambuc
10f4a2713aSLionel Sambuc#ifdef MODULE_H_MACRO
11f4a2713aSLionel Sambuc#  error MODULE_H_MACRO should have been hidden
12f4a2713aSLionel Sambuc#endif
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc#ifdef DEPENDS_ON_MODULE
15f4a2713aSLionel Sambuc#  error DEPENDS_ON_MODULE should have been hidden
16f4a2713aSLionel Sambuc#endif
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc#ifdef ERRORS
19f4a2713aSLionel SambucModule *mod; // expected-error{{declaration of 'Module' must be imported from module 'Module' before it is required}}
20f4a2713aSLionel Sambuc// expected-note@Inputs/Module.framework/Headers/Module.h:15 {{previous}}
21f4a2713aSLionel Sambuc#else
22f4a2713aSLionel Sambuc#import <AlsoDependsOnModule/AlsoDependsOnModule.h> // expected-warning{{treating #import as an import of module 'AlsoDependsOnModule'}}
23f4a2713aSLionel Sambuc#endif
24f4a2713aSLionel SambucModule *mod2;
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambucint getDependsOther() { return depends_on_module_other; }
27f4a2713aSLionel Sambuc
28f4a2713aSLionel Sambucvoid testSubframeworkOther() {
29f4a2713aSLionel Sambuc#ifdef ERRORS
30f4a2713aSLionel Sambuc  double *sfo1 = sub_framework_other; // expected-error{{declaration of 'sub_framework_other' must be imported from module 'DependsOnModule.SubFramework.Other'}}
31f4a2713aSLionel Sambuc  // expected-note@Inputs/DependsOnModule.framework/Frameworks/SubFramework.framework/Headers/Other.h:15 {{previous}}
32f4a2713aSLionel Sambuc#endif
33f4a2713aSLionel Sambuc}
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc// Test umbrella-less submodule includes
36f4a2713aSLionel Sambuc#include <NoUmbrella/A.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.A'}}
37f4a2713aSLionel Sambucint getNoUmbrellaA() { return no_umbrella_A; }
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambuc// Test umbrella-less submodule includes
40f4a2713aSLionel Sambuc#include <NoUmbrella/SubDir/C.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.SubDir.C'}}
41f4a2713aSLionel Sambucint getNoUmbrellaC() { return no_umbrella_C; }
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc#ifndef ERRORS
44f4a2713aSLionel Sambuc// Test header cross-subframework include pattern.
45f4a2713aSLionel Sambuc#include <DependsOnModule/../Frameworks/SubFramework.framework/Headers/Other.h> // expected-warning{{treating #include as an import of module 'DependsOnModule.SubFramework.Other'}}
46f4a2713aSLionel Sambuc#endif
47f4a2713aSLionel Sambuc
48f4a2713aSLionel Sambucvoid testSubframeworkOtherAgain() {
49f4a2713aSLionel Sambuc  double *sfo1 = sub_framework_other;
50f4a2713aSLionel Sambuc}
51f4a2713aSLionel Sambuc
52f4a2713aSLionel Sambucvoid testModuleSubFramework() {
53f4a2713aSLionel Sambuc  char *msf = module_subframework;
54f4a2713aSLionel Sambuc}
55f4a2713aSLionel Sambuc
56f4a2713aSLionel Sambuc#include <Module/../Frameworks/SubFramework.framework/Headers/SubFramework.h> // expected-warning{{treating #include as an import of module 'Module.SubFramework'}}
57f4a2713aSLionel Sambuc
58f4a2713aSLionel Sambucvoid testModuleSubFrameworkAgain() {
59f4a2713aSLionel Sambuc  char *msf = module_subframework;
60f4a2713aSLionel Sambuc}
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambuc// Test inclusion of private headers.
63f4a2713aSLionel Sambuc#include <DependsOnModule/DependsOnModulePrivate.h> // expected-warning{{treating #include as an import of module 'DependsOnModule.Private.DependsOnModule'}}
64f4a2713aSLionel Sambuc
65f4a2713aSLionel Sambucint getDependsOnModulePrivate() { return depends_on_module_private; }
66f4a2713aSLionel Sambuc
67f4a2713aSLionel Sambuc#include <Module/ModulePrivate.h> // includes the header
68f4a2713aSLionel Sambuc
69f4a2713aSLionel Sambucint getModulePrivate() { return module_private; }
70f4a2713aSLionel Sambuc
71f4a2713aSLionel Sambuc#include <NoUmbrella/A_Private.h> // expected-warning{{treating #include as an import of module 'NoUmbrella.Private.A_Private'}}
72f4a2713aSLionel Sambucint getNoUmbrellaAPrivate() { return no_umbrella_A_private; }
73f4a2713aSLionel Sambuc
74f4a2713aSLionel Sambucint getNoUmbrellaBPrivateFail() { return no_umbrella_B_private; } // expected-error{{declaration of 'no_umbrella_B_private' must be imported from module 'NoUmbrella.Private.B_Private'}}
75f4a2713aSLionel Sambuc// expected-note@Inputs/NoUmbrella.framework/PrivateHeaders/B_Private.h:1 {{previous}}
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc// Test inclusion of headers that are under an umbrella directory but
78f4a2713aSLionel Sambuc// not actually part of the module.
79f4a2713aSLionel Sambuc#include <Module/NotInModule.h> // expected-warning{{treating #include as an import of module 'Module.NotInModule'}} \
80f4a2713aSLionel Sambuc  // expected-warning{{missing submodule 'Module.NotInModule'}}
81f4a2713aSLionel Sambuc
82f4a2713aSLionel Sambucint getNotInModule() {
83f4a2713aSLionel Sambuc  return not_in_module;
84f4a2713aSLionel Sambuc}
85f4a2713aSLionel Sambuc
86*0a6a1f1dSLionel Sambucvoid includeNotAtTopLevel() { // expected-note {{to match this '{'}}
87*0a6a1f1dSLionel Sambuc  #include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} expected-error {{expected '}'}}
88*0a6a1f1dSLionel Sambuc} // expected-error {{extraneous closing brace}}
89