summaryrefslogtreecommitdiff
path: root/test/SemaCXX/using-directive.cpp
blob: 22c6e14ce54f6a98012c7b085099b9e029b6b24e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// RUN: %clang_cc1 -fsyntax-only -verify %s

namespace A {
  short i; // expected-note 2{{candidate found by name lookup is 'A::i'}}
  namespace B {
    long i; // expected-note{{candidate found by name lookup is 'A::B::i'}}
    void f() {} // expected-note{{candidate function}}
    int k;
    namespace E {} // \
      expected-note{{candidate found by name lookup is 'A::B::E'}}
  }

  namespace E {} // expected-note{{candidate found by name lookup is 'A::E'}}

  namespace C {
    using namespace B;
    namespace E {} // \
      expected-note{{candidate found by name lookup is 'A::C::E'}}
  }

  void f() {} // expected-note{{candidate function}}

  class K1 {
    void foo();
  };

  void local_i() {
    char i;
    using namespace A;
    using namespace B;
    int a[sizeof(i) == sizeof(char)? 1 : -1]; // okay
  }
  namespace B {
    int j;
  }

  void ambig_i() {
    using namespace A;
    using namespace A::B;
    (void) i; // expected-error{{reference to 'i' is ambiguous}}
    f(); // expected-error{{call to 'f' is ambiguous}}
    (void) j; // okay
    using namespace C;
    (void) k; // okay
    using namespace E; // expected-error{{reference to 'E' is ambiguous}}
  }

  struct K2 {}; // expected-note 2{{candidate found by name lookup is 'A::K2'}}
}

struct K2 {}; // expected-note 2{{candidate found by name lookup is 'K2'}}

using namespace A;

void K1::foo() {} // okay

struct K2 *k2; // expected-error{{reference to 'K2' is ambiguous}}

K2 *k3; // expected-error{{reference to 'K2' is ambiguous}}

class X { // expected-note{{candidate found by name lookup is 'X'}}
  // FIXME: produce a suitable error message for this
  using namespace A; // expected-error{{not allowed}}
};

namespace N {
  struct K2;
  struct K2 { };
}

namespace Ni {
 int i(); // expected-note{{candidate found by name lookup is 'Ni::i'}}
}

namespace NiTest {
 using namespace A;
 using namespace Ni;

 int test() {
   return i; // expected-error{{reference to 'i' is ambiguous}}
 }
}

namespace OneTag {
  struct X; // expected-note{{candidate found by name lookup is 'OneTag::X'}}
}

namespace OneFunction {
  void X(); // expected-note{{candidate found by name lookup is 'OneFunction::X'}}
}

namespace TwoTag {
  struct X; // expected-note{{candidate found by name lookup is 'TwoTag::X'}}
}

namespace FuncHidesTagAmbiguity {
  using namespace OneTag;
  using namespace OneFunction;
  using namespace TwoTag;

  void test() {
    (void)X(); // expected-error{{reference to 'X' is ambiguous}}
  }
}

// PR5479
namespace Aliased {
  void inAliased();
}
namespace Alias = Aliased;
using namespace Alias;
void testAlias() {
  inAliased();
}

namespace N { void f2(int); }

extern "C++" {
  using namespace N;
  void f3() { f2(1); }
}

void f4() { f2(1); }

// PR7517
using namespace std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}}
using namespace ::std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}}

namespace test1 {
  namespace ns { typedef int test1; }
  template <class T> using namespace ns; // expected-error {{cannot template a using directive}}

  // Test that we recovered okay.
  test1 x;
}