p8.cpp revision fe4ea55700c806493bebbf7bbfe07ce4b7339a3e
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2 3struct Opaque0 {}; 4struct Opaque1 {}; 5 6// Redeclarations are okay in a namespace. 7namespace test0 { 8 namespace ns { 9 void foo(Opaque0); // expected-note 2 {{candidate function}} 10 } 11 12 using ns::foo; 13 using ns::foo; 14 15 void test0() { 16 foo(Opaque1()); // expected-error {{no matching function for call}} 17 } 18 19 namespace ns { 20 void foo(Opaque1); 21 } 22 23 void test1() { 24 foo(Opaque1()); // expected-error {{no matching function for call}} 25 } 26 27 using ns::foo; 28 29 void test2() { 30 foo(Opaque1()); 31 } 32 33 using ns::foo; 34} 35 36// Make sure we handle transparent contexts the same way. 37namespace test1 { 38 namespace ns { 39 void foo(Opaque0); // expected-note 2 {{candidate function}} 40 } 41 42 extern "C++" { 43 using ns::foo; 44 } 45 46 void test0() { 47 foo(Opaque1()); // expected-error {{no matching function for call}} 48 } 49 50 namespace ns { 51 void foo(Opaque1); 52 } 53 54 void test1() { 55 foo(Opaque1()); // expected-error {{no matching function for call}} 56 } 57 58 extern "C++" { 59 using ns::foo; 60 } 61 62 void test2() { 63 foo(Opaque1()); 64 } 65} 66 67// Make sure we detect invalid redeclarations that can't be detected 68// until template instantiation. 69namespace test2 { 70 template <class T> struct Base { 71 typedef Base type; 72 void foo(); 73 }; 74 75 template <class T> struct Derived : Base<T> { 76 // These are invalid redeclarations, detectable only after 77 // instantiation. 78 using Base<T>::foo; // expected-note {{previous using decl}} 79 using Base<T>::type::foo; //expected-error {{redeclaration of using decl}} 80 }; 81 82 template struct Derived<int>; // expected-note {{in instantiation of template class}} 83} 84 85// PR8668: redeclarations are not okay in a function. 86namespace test3 { 87 namespace N { 88 int f(int); 89 typedef int type; 90 } 91 92 void g() { 93 using N::f; // expected-note {{previous using declaration}} 94 using N::f; // expected-error {{redeclaration of using decl}} 95 using N::type; // expected-note {{previous using declaration}} 96 using N::type; // expected-error {{redeclaration of using decl}} 97 } 98 99 void h() { 100 using N::f; 101 using N::type; 102 { 103 using N::f; 104 using N::type; 105 } 106 } 107} 108