164 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s2 3template<typename T> struct A {4 void f() { }5 struct N { }; // expected-note{{target of using declaration}}6};7 8template<typename T> struct B : A<T> {9 using A<T>::f;10 using A<T>::N; // expected-error{{dependent using declaration resolved to type without 'typename'}}11 12 using A<T>::foo; // expected-error{{no member named 'foo'}}13 using A<double>::f; // expected-error{{using declaration refers into 'A<double>', which is not a base class of 'B<int>'}}14};15 16B<int> a; // expected-note{{in instantiation of template class 'B<int>' requested here}}17 18template<typename T> struct C : A<T> {19 using A<T>::f;20 21 void f() { };22};23 24template <typename T> struct D : A<T> {25 using A<T>::f;26 27 void f();28};29 30template<typename T> void D<T>::f() { }31 32template<typename T> struct E : A<T> {33 using A<T>::f;34 35 void g() { f(); }36};37 38namespace test0 {39 struct Base {40 int foo;41 };42 template<typename T> struct E : Base {43 using Base::foo;44 };45 46 template struct E<int>;47}48 49// PR789650namespace PR7896 {51template <class T> struct Foo {52 int k (float);53};54struct Baz {55 int k (int);56};57template <class T> struct Bar : public Foo<T>, Baz {58 using Foo<T>::k;59 using Baz::k;60 int foo() {61 return k (1.0f);62 }63};64template int Bar<int>::foo();65}66 67// PR1088368namespace PR10883 {69 template <typename T>70 class Base {71 public:72 typedef long Container;73 };74 75 template <typename T>76 class Derived : public Base<T> {77 public:78 using Base<T>::Container;79 80 void foo(const Container& current); // expected-error {{unknown type name 'Container'}}81 };82}83 84template<typename T> class UsingTypenameNNS {85 using typename T::X;86 typename X::X x;87};88 89namespace aliastemplateinst {90 template<typename T> struct A { };91 template<typename T> using APtr = A<T*>; // expected-note{{previous use is here}}92 93 template struct APtr<int>; // expected-error{{alias template 'APtr' cannot be referenced with the 'struct' specifier}}94}95 96namespace DontDiagnoseInvalidTest {97template <bool Value> struct Base {98 static_assert(Value, ""); // expected-error {{static assertion failed}}99};100struct Derived : Base<false> { // expected-note {{requested here}}101 using Base<false>::Base; // OK. Don't diagnose that 'Base' isn't a base class of Derived.102};103} // namespace DontDiagnoseInvalidTest104 105namespace shadow_nested_operator {106template <typename T>107struct A {108 struct Nested {};109 operator Nested*() {return 0;};110};111 112template <typename T>113struct B : A<T> {114 using A<T>::operator typename A<T>::Nested*;115 operator typename A<T>::Nested *() {116 struct A<T> * thi = this;117 return *thi;118 };119};120 121int foo () {122 struct B<int> b;123 auto s = *b;124}125} // namespace shadow_nested_operator126 127namespace func_templ {128namespace sss {129double foo(int, double);130template <class T>131T foo(T);132} // namespace sss133 134namespace oad {135void foo();136}137 138namespace oad {139using sss::foo;140}141 142namespace sss {143using oad::foo;144}145 146namespace sss {147double foo(int, double) { return 0; }148// There used to be an error with the below declaration when the example should149// be accepted.150template <class T>151T foo(T t) { // OK152 return t;153}154} // namespace sss155} // namespace func_templ156 157namespace DependentName {158 template <typename T> struct S {159 using typename T::Ty;160 static Ty Val;161 };162 template <typename T> typename S<T>::Ty S<T>::Val;163} // DependentName164