xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/namespace.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc namespace A { // expected-note 2 {{previous definition is here}}
3*f4a2713aSLionel Sambuc   int A;
f()4*f4a2713aSLionel Sambuc   void f() { A = 0; }
5*f4a2713aSLionel Sambuc }
6*f4a2713aSLionel Sambuc 
f()7*f4a2713aSLionel Sambuc void f() { A = 0; } // expected-error {{unexpected namespace name 'A': expected expression}}
8*f4a2713aSLionel Sambuc int A; // expected-error {{redefinition of 'A' as different kind of symbol}}
9*f4a2713aSLionel Sambuc class A; // expected-error {{redefinition of 'A' as different kind of symbol}}
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc class B {}; // expected-note {{previous definition is here}} \
12*f4a2713aSLionel Sambuc             // expected-note{{candidate function (the implicit copy assignment operator)}}
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc void C(); // expected-note {{previous definition is here}}
15*f4a2713aSLionel Sambuc namespace C {} // expected-error {{redefinition of 'C' as different kind of symbol}}
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc namespace D {
18*f4a2713aSLionel Sambuc   class D {};
19*f4a2713aSLionel Sambuc }
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc namespace S1 {
22*f4a2713aSLionel Sambuc   int x;
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc   namespace S2 {
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc     namespace S3 {
27*f4a2713aSLionel Sambuc       B x;
28*f4a2713aSLionel Sambuc     }
29*f4a2713aSLionel Sambuc   }
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc namespace S1 {
f()33*f4a2713aSLionel Sambuc   void f() {
34*f4a2713aSLionel Sambuc     x = 0;
35*f4a2713aSLionel Sambuc   }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc   namespace S2 {
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc     namespace S3 {
f()40*f4a2713aSLionel Sambuc       void f() {
41*f4a2713aSLionel Sambuc         x = 0; // expected-error {{no viable overloaded '='}}
42*f4a2713aSLionel Sambuc       }
43*f4a2713aSLionel Sambuc     }
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc     int y;
46*f4a2713aSLionel Sambuc   }
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc namespace S1 {
50*f4a2713aSLionel Sambuc   namespace S2 {
51*f4a2713aSLionel Sambuc     namespace S3 {
f3()52*f4a2713aSLionel Sambuc       void f3() {
53*f4a2713aSLionel Sambuc         y = 0;
54*f4a2713aSLionel Sambuc       }
55*f4a2713aSLionel Sambuc     }
56*f4a2713aSLionel Sambuc   }
57*f4a2713aSLionel Sambuc }
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc namespace B {} // expected-error {{redefinition of 'B' as different kind of symbol}}
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc namespace foo {
63*f4a2713aSLionel Sambuc   enum x {
64*f4a2713aSLionel Sambuc     Y
65*f4a2713aSLionel Sambuc   };
66*f4a2713aSLionel Sambuc }
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc static foo::x  test1;  // ok
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc static foo::X  test2;  // typo: expected-error {{no type named 'X' in}}
71*f4a2713aSLionel Sambuc 
72*f4a2713aSLionel Sambuc namespace PR6620 {
73*f4a2713aSLionel Sambuc   namespace numeric {
74*f4a2713aSLionel Sambuc     namespace op {
75*f4a2713aSLionel Sambuc       struct greater {};
76*f4a2713aSLionel Sambuc     }
77*f4a2713aSLionel Sambuc     namespace {
78*f4a2713aSLionel Sambuc       extern op::greater const greater;
79*f4a2713aSLionel Sambuc     }
80*f4a2713aSLionel Sambuc   }
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc   namespace numeric {
83*f4a2713aSLionel Sambuc     namespace {
84*f4a2713aSLionel Sambuc       op::greater const greater = op::greater();
85*f4a2713aSLionel Sambuc     }
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc     template<typename T, typename U>
f(T & l,U & r)88*f4a2713aSLionel Sambuc     int f(T& l, U& r)
89*f4a2713aSLionel Sambuc     { numeric::greater(l, r); }
90*f4a2713aSLionel Sambuc 
91*f4a2713aSLionel Sambuc   }
92*f4a2713aSLionel Sambuc }
93