blob: 2e2bd8a75e20ff5593c60125a0fabd971c3d016b [file] [log] [blame]
Douglas Gregor55368912011-12-14 16:03:29 +00001// RUN: rm -rf %t
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002// RUN: %clang_cc1 -fmodules -fobjc-arc -I %S/Inputs -fmodules-cache-path=%t %s -verify -DUSE_1 -DUSE_2 -DUSE_3 -DUSE_4
3// RUN: %clang_cc1 -fmodules -fobjc-arc -I %S/Inputs -fmodules-cache-path=%t %s -verify -DUSE_2 -DUSE_3 -DUSE_4
4// RUN: %clang_cc1 -fmodules -fobjc-arc -I %S/Inputs -fmodules-cache-path=%t %s -verify -DUSE_3 -DUSE_4
5// RUN: %clang_cc1 -fmodules -fobjc-arc -I %S/Inputs -fmodules-cache-path=%t %s -verify -DUSE_4
Douglas Gregor55368912011-12-14 16:03:29 +00006
Stephen Hines6bcf27b2014-05-29 04:14:42 -07007// expected-note@Inputs/def.h:5 0-1{{previous}}
8// expected-note@Inputs/def.h:16 0-1{{previous}}
9// expected-note@Inputs/def-include.h:11 0-1{{previous}}
Douglas Gregord07cc362012-01-02 17:18:37 +000010
Douglas Gregor6bd99292013-02-09 01:35:03 +000011@class Def;
12Def *def;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070013class Def2; // expected-note 0-1{{forward decl}}
Douglas Gregor6bd99292013-02-09 01:35:03 +000014Def2 *def2;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070015namespace Def3NS { class Def3; } // expected-note 0-1{{forward decl}}
Richard Smithb7165582013-09-09 07:34:56 +000016Def3NS::Def3 *def3;
Douglas Gregor6bd99292013-02-09 01:35:03 +000017
18@interface Unrelated
19- defMethod;
20@end
21
Douglas Gregor1b257af2012-12-11 22:11:52 +000022@import decldef;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070023#ifdef USE_1
Richard Smithd67679d2013-08-20 20:35:18 +000024A *a1; // expected-error{{declaration of 'A' must be imported from module 'decldef.Def'}}
25B *b1;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070026#define USED
Richard Smithd67679d2013-08-20 20:35:18 +000027#endif
Douglas Gregor1b257af2012-12-11 22:11:52 +000028@import decldef.Decl;
Douglas Gregor55368912011-12-14 16:03:29 +000029
Douglas Gregord63348c2011-12-15 20:36:27 +000030A *a2;
Douglas Gregor55368912011-12-14 16:03:29 +000031B *b;
32
Douglas Gregord07cc362012-01-02 17:18:37 +000033void testA(A *a) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070034#ifdef USE_2
Richard Smithd67679d2013-08-20 20:35:18 +000035 a->ivar = 17;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070036 #ifndef USED
Richard Smithd67679d2013-08-20 20:35:18 +000037 // expected-error@-2{{definition of 'A' must be imported from module 'decldef.Def' before it is required}}
Stephen Hines6bcf27b2014-05-29 04:14:42 -070038 #define USED
39 #endif
Richard Smithd67679d2013-08-20 20:35:18 +000040#endif
Douglas Gregord07cc362012-01-02 17:18:37 +000041}
42
Douglas Gregor55368912011-12-14 16:03:29 +000043void testB() {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070044#ifdef USE_3
45 B b;
46 #ifndef USED
47 // expected-error@-2{{definition of 'B' must be imported from module 'decldef.Def' before it is required}}
48 #define USED
49 #endif
50#endif
Douglas Gregor55368912011-12-14 16:03:29 +000051}
Douglas Gregor6bd99292013-02-09 01:35:03 +000052
53void testDef() {
54 [def defMethod];
55}
56
57void testDef2() {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070058#ifdef USE_4
59 def2->func();
60 def3->func();
61 #ifndef USED
62 // expected-error@-3 {{definition of 'Def2' must be imported}}
63 #define USED
64 #endif
65#endif
Douglas Gregor6bd99292013-02-09 01:35:03 +000066}