1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3// (this actually occurs before paragraph 1)
4namespace test0 {
5  namespace A {}
6  class B {
7    using namespace A; // expected-error {{'using namespace' is not allowed in classes}}
8  };
9}
10
11
12struct opaque0 {};
13struct opaque1 {};
14
15// Test that names appear as if in deepest common ancestor.
16namespace test1 {
17  namespace A {
18    namespace B {
19      opaque0 foo(); // expected-note {{candidate}}
20    }
21  }
22
23  namespace C {
24    opaque1 foo(); // expected-note {{candidate}}
25
26    opaque1 test() {
27      using namespace A::B;
28      return foo(); // C::foo
29    }
30  }
31
32  opaque1 test() {
33    using namespace A::B;
34    using namespace C;
35    return foo(); // expected-error {{call to 'foo' is ambiguous}}
36  }
37}
38
39// Same thing, but with the directives in namespaces.
40namespace test2 {
41  namespace A {
42    namespace B {
43      opaque0 foo(); // expected-note {{candidate}}
44    }
45  }
46
47  namespace C {
48    opaque1 foo(); // expected-note {{candidate}}
49
50    namespace test {
51      using namespace A::B;
52
53      opaque1 test() {
54        return foo(); // C::foo
55      }
56    }
57  }
58
59  namespace test {
60    using namespace A::B;
61    using namespace C;
62
63    opaque1 test() {
64      return foo(); // expected-error {{call to 'foo' is ambiguous}}
65    }
66  }
67}
68
69// Transitivity.
70namespace test3 {
71  namespace A {
72    namespace B {
73      opaque0 foo();
74    }
75  }
76  namespace C {
77    using namespace A;
78  }
79
80  opaque0 test0() {
81    using namespace C;
82    using namespace B;
83    return foo();
84  }
85
86  namespace D {
87    using namespace C;
88  }
89  namespace A {
90    opaque1 foo();
91  }
92
93  opaque1 test1() {
94    using namespace D;
95    return foo();
96  }
97}
98
99// Transitivity acts like synthetic using directives.
100namespace test4 {
101  namespace A {
102    namespace B {
103      opaque0 foo(); // expected-note {{candidate}}
104    }
105  }
106
107  namespace C {
108    using namespace A::B;
109  }
110
111  opaque1 foo(); // expected-note {{candidate}}
112
113  namespace A {
114    namespace D {
115      using namespace C;
116    }
117
118    opaque0 test() {
119      using namespace D;
120      return foo();
121    }
122  }
123
124  opaque0 test() {
125    using namespace A::D;
126    return foo(); // expected-error {{call to 'foo' is ambiguous}}
127  }
128}
129
130// Bug: using directives should be followed when parsing default
131// arguments in scoped declarations.
132class test5 {
133  int inc(int x);
134};
135namespace Test5 {
136  int default_x = 0;
137}
138using namespace Test5;
139int test5::inc(int x = default_x) {
140  return x+1;
141}
142