Home | History | Annotate | Download | only in namespace.udecl
      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 
     13 namespace test0 {
     14   namespace ns { void foo(); } // expected-note {{target of using declaration}}
     15   int foo(void); // expected-note {{conflicting declaration}}
     16   using ns::foo; // expected-error {{target of using declaration conflicts with declaration already in scope}}
     17 }
     18 
     19 namespace test1 {
     20   namespace ns { void foo(); } // expected-note {{target of using declaration}}
     21   using ns::foo; //expected-note {{using declaration}}
     22   int foo(void); // expected-error {{declaration conflicts with target of using declaration already in scope}}
     23 }
     24 
     25 namespace test2 {
     26   namespace ns { void foo(); } // expected-note 2 {{target of using declaration}}
     27   void test0() {
     28     int foo(void); // 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(void); // expected-error {{declaration conflicts with target of using declaration already in scope}}
     35   }
     36 }
     37 
     38 namespace test3 {
     39   namespace ns { void foo(); } // expected-note 2 {{target of using declaration}}
     40   class Test0 {
     41     void test() {
     42       int foo(void); // 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(void); // expected-error {{declaration conflicts with target of using declaration already in scope}}
     51     }
     52   };
     53 }
     54 
     55 namespace test4 {
     56   namespace ns { void foo(); } // expected-note 2 {{target of using declaration}}
     57   template <typename> class Test0 {
     58     void test() {
     59       int foo(void); // 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(void); // 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 namespace test5 {
     74   namespace ns { void foo(int); }
     75   template <typename T> class Test0 {
     76     void test() {
     77       int foo(T);
     78       using ns::foo;
     79     }
     80   };
     81 
     82   template <typename T> class Test1 {
     83     void test() {
     84       using ns::foo;
     85       int foo(T);
     86     }
     87   };
     88 
     89   template class Test0<int>;
     90   template class Test1<int>;
     91 }
     92