1// RUN: %clang_cc1 -fsyntax-only -verify %s
2namespace Ns {
3  int f(); // expected-note{{previous declaration is here}}
4
5  enum E {
6    Enumerator
7  };
8}
9namespace Ns {
10  double f(); // expected-error{{functions that differ only in their return type cannot be overloaded}}
11
12  int x = Enumerator;
13}
14
15namespace Ns2 {
16  float f();
17}
18
19int y = Ns::Enumerator;
20
21namespace 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;
36
37    typedef int type;
38
39    void foo(type);
40  };
41
42  void test_f1() {
43    int &i1 = f1();
44  }
45}
46
47void N::f1::foo(int i) {
48  f1::member = i;
49  f1::type &ir = i;
50}
51
52namespace N {
53  float& f1(int x) {
54    N::f1::type& i1 = x;
55    f1::type& i2 = x;
56  }
57
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);
72  int v3 = ::i1;
73  int v4 = N::f1::member;
74}
75
76typedef int f2_type;
77namespace a {
78  typedef int f2_type(int, int);
79
80  void test_f2() {
81    ::f2_type(1, 2); // expected-error {{excess elements in scalar initializer}}
82  }
83}
84
85// PR clang/3291
86namespace a {
87  namespace a {   // A1
88    namespace a { // A2
89      int i; // expected-note{{'a::a::a::i' declared here}}
90    }
91  }
92}
93
94void test_a() {
95  a::a::i = 3; // expected-error{{no member named 'i' in namespace 'a::a'; did you mean 'a::a::a::i'?}}
96  a::a::a::i = 4;
97  a::a::j = 3; // expected-error-re{{no member named 'j' in namespace 'a::a'{{$}}}}
98}
99
100struct Undef { // expected-note{{definition of 'Undef' is not complete until the closing '}'}}
101  typedef int type;
102
103  Undef::type member;
104
105  static int size = sizeof(Undef); // expected-error{{invalid application of 'sizeof' to an incomplete type 'Undef'}}
106
107  int f();
108};
109
110int Undef::f() {
111  return sizeof(Undef);
112}
113
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}
128
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}
150
151namespace pr12339 {
152  extern "C" void i; // expected-error{{variable has incomplete type 'void'}}
153  pr12339::FOO  // expected-error{{no type named 'FOO' in namespace 'pr12339'}}
154}  // expected-error{{expected unqualified-id}}
155