p11.cpp revision 1d7bcf4b35f8bc0a0a40f4ea7b06b55c63725108
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3// C++03 [namespace.udecl]p11:
4//   If a function declaration in namespace scope or block scope has
5//   the same name and the same parameter types as a function
6//   introduced by a using-declaration, the program is
7//   ill-formed. [Note: two using-declarations may introduce functions
8//   with the same name and the same parameter types. If, for a call
9//   to an unqualified function name, function overload resolution
10//   selects the functions introduced by such using-declarations, the
11//   function call is ill-formed.
12
13namespace test0 {
14  namespace ns { void foo(); } // expected-note {{target of using declaration}}
15  int foo(); // expected-note {{conflicting declaration}}
16  using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}}
17}
18
19namespace test1 {
20  namespace ns { void foo(); } // expected-note {{target of using declaration}}
21  using ns::foo; //expected-note {{using declaration}}
22  int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
23}
24
25namespace test2 {
26  namespace ns { void foo(); } // expected-note 2 {{target of using declaration}}
27  void test0() {
28    int foo(); // expected-note {{conflicting declaration}}
29    using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}}
30  }
31
32  void test1() {
33    using ns::foo; //expected-note {{using declaration}}
34    int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
35  }
36}
37
38namespace test3 {
39  namespace ns { void foo(); } // expected-note 2 {{target of using declaration}}
40  class Test0 {
41    void test() {
42      int foo(); // expected-note {{conflicting declaration}}
43      using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}}
44    }
45  };
46
47  class Test1 {
48    void test() {
49      using ns::foo; //expected-note {{using declaration}}
50      int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
51    }
52  };
53}
54
55namespace test4 {
56  namespace ns { void foo(); } // expected-note 2 {{target of using declaration}}
57  template <typename> class Test0 {
58    void test() {
59      int foo(); // expected-note {{conflicting declaration}}
60      using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}}
61    }
62  };
63
64  template <typename> class Test1 {
65    void test() {
66      using ns::foo; //expected-note {{using declaration}}
67      int foo(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
68    }
69  };
70}
71
72// FIXME: we should be able to diagnose both of these, but we can't.
73// ...I'm actually not sure why we can diagnose either of them; it's
74// probably a bug.
75namespace test5 {
76  namespace ns { void foo(int); } // expected-note {{target of using declaration}}
77  template <typename T> class Test0 {
78    void test() {
79      int foo(T);
80      using ns::foo;
81    }
82  };
83
84  template <typename T> class Test1 {
85    void test() {
86      using ns::foo; // expected-note {{using declaration}}
87      int foo(T); // expected-error {{declaration conflicts with target of using declaration already in scope}}
88    }
89  };
90
91  template class Test0<int>;
92  template class Test1<int>; // expected-note {{in instantiation of member function}}
93}
94