blob: a14193cc7ac88b1b5d20946418bcf93db28da48c [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor44b43212008-12-11 16:49:14 +00002namespace Ns {
3 int f(); // expected-note{{previous declaration is here}}
Douglas Gregor074149e2009-01-05 19:45:36 +00004
5 enum E {
6 Enumerator
7 };
Douglas Gregor44b43212008-12-11 16:49:14 +00008}
9namespace Ns {
10 double f(); // expected-error{{functions that differ only in their return type cannot be overloaded}}
Douglas Gregor074149e2009-01-05 19:45:36 +000011
12 int x = Enumerator;
Douglas Gregor44b43212008-12-11 16:49:14 +000013}
14
15namespace Ns2 {
16 float f();
17}
18
Douglas Gregor074149e2009-01-05 19:45:36 +000019int y = Ns::Enumerator;
20
Douglas Gregor44b43212008-12-11 16:49:14 +000021namespace Ns2 {
22 float f(int); // expected-note{{previous declaration is here}}
23}
24
25namespace Ns2 {
26 double f(int); // expected-error{{functions that differ only in their return type cannot be overloaded}}
27}
28
29namespace N {
30 int& f1();
31}
32
33namespace N {
34 struct f1 {
35 static int member;
Douglas Gregor518fda12009-01-13 05:10:00 +000036
37 typedef int type;
38
39 void foo(type);
Douglas Gregor44b43212008-12-11 16:49:14 +000040 };
41
42 void test_f1() {
43 int &i1 = f1();
44 }
45}
46
Douglas Gregor0b7a1582009-01-17 00:42:38 +000047void N::f1::foo(int i) {
48 f1::member = i;
49 f1::type &ir = i;
50}
Douglas Gregor518fda12009-01-13 05:10:00 +000051
Douglas Gregor44b43212008-12-11 16:49:14 +000052namespace N {
Douglas Gregor518fda12009-01-13 05:10:00 +000053 float& f1(int x) {
54 N::f1::type& i1 = x;
Douglas Gregoreb11cd02009-01-14 22:20:51 +000055 f1::type& i2 = x;
Douglas Gregor518fda12009-01-13 05:10:00 +000056 }
Douglas Gregor44b43212008-12-11 16:49:14 +000057
58 struct f2 {
59 static int member;
60 };
61 void f2();
62}
63
64int i1 = N::f1::member;
65typedef struct N::f1 type1;
66int i2 = N::f2::member;
67typedef struct N::f2 type2;
68
69void test_f1(int i) {
70 int &v1 = N::f1();
71 float &v2 = N::f1(i);
Chris Lattnera67865c2009-01-05 00:59:08 +000072 int v3 = ::i1;
Douglas Gregor1a49af92009-01-06 05:10:23 +000073 int v4 = N::f1::member;
Douglas Gregor44b43212008-12-11 16:49:14 +000074}
Chris Lattnera67865c2009-01-05 00:59:08 +000075
Chris Lattner83cf05a2009-01-05 01:42:04 +000076typedef int f2_type;
77namespace a {
78 typedef int f2_type(int, int);
79
80 void test_f2() {
Douglas Gregor19311e72010-09-08 21:40:08 +000081 ::f2_type(1, 2); // expected-error {{excess elements in scalar initializer}}
Chris Lattner83cf05a2009-01-05 01:42:04 +000082 }
83}
84
Douglas Gregorbc468ba2009-01-07 21:36:02 +000085// PR clang/3291
86namespace a {
87 namespace a { // A1
88 namespace a { // A2
Kaelyn Uhrain8d3607b2012-06-06 20:54:51 +000089 int i; // expected-note{{'::a::a::a::i' declared here}}
Douglas Gregorbc468ba2009-01-07 21:36:02 +000090 }
91 }
92}
Chris Lattner83cf05a2009-01-05 01:42:04 +000093
Douglas Gregorbc468ba2009-01-07 21:36:02 +000094void test_a() {
Kaelyn Uhrain8d3607b2012-06-06 20:54:51 +000095 a::a::i = 3; // expected-error{{no member named 'i' in namespace 'a::a'; did you mean '::a::a::a::i'?}}
Douglas Gregorbc468ba2009-01-07 21:36:02 +000096 a::a::a::i = 4;
Kaelyn Uhrain8d3607b2012-06-06 20:54:51 +000097 a::a::j = 3; // expected-error-re{{no member named 'j' in namespace 'a::a'$}}
Douglas Gregorbc468ba2009-01-07 21:36:02 +000098}
99
John McCall7c2342d2010-03-10 11:27:22 +0000100struct Undef { // expected-note{{definition of 'Undef' is not complete until the closing '}'}}
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000101 typedef int type;
102
103 Undef::type member;
104
John McCall7c2342d2010-03-10 11:27:22 +0000105 static int size = sizeof(Undef); // expected-error{{invalid application of 'sizeof' to an incomplete type 'Undef'}}
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000106
107 int f();
108};
109
110int Undef::f() {
111 return sizeof(Undef);
112}
John McCall336e7742009-12-02 19:59:55 +0000113
114// PR clang/5667
115namespace test1 {
116 template <typename T> struct is_class {
117 enum { value = 0 };
118 };
119
120 template <typename T> class ClassChecker {
121 bool isClass() {
122 return is_class<T>::value;
123 }
124 };
125
126 template class ClassChecker<int>;
127}
Douglas Gregor4074eef2010-04-23 02:08:13 +0000128
129namespace PR6830 {
130 namespace foo {
131
132 class X {
133 public:
134 X() {}
135 };
136
137 } // namespace foo
138
139 class Z {
140 public:
141 explicit Z(const foo::X& x) {}
142
143 void Work() {}
144 };
145
146 void Test() {
147 Z(foo::X()).Work();
148 }
149}
Nick Lewycky173a37a2012-04-03 21:44:08 +0000150
151namespace pr12339 {
152 extern "C" void i;
153 pr12339::FOO // expected-error{{no type named 'FOO' in namespace 'pr12339'}}
154} // expected-error{{expected unqualified-id}}