brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · 28d8376 Raw
170 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s2// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s3 4namespace test0 {5  namespace N { }6 7  template<typename T>8  struct A {9    void f();10  };11 12  template<typename T>13  struct B : A<T> {14    using A<T>::f;15 16    void g() {17      using namespace N;18      f();19    }20  };21 22  template struct B<int>;23}24 25namespace test1 {26  template <class Derived> struct Visitor1 {27    void Visit(struct Object1*);28  };29  template <class Derived> struct Visitor2 {30    void Visit(struct Object2*); // expected-note {{candidate function}}31  };32 33  template <class Derived> struct JoinVisitor34      : Visitor1<Derived>, Visitor2<Derived> {35    typedef Visitor1<Derived> Base1;36    typedef Visitor2<Derived> Base2;37 38    void Visit(struct Object1*);  // expected-note {{candidate function}}39    using Base2::Visit;40  };41 42  class Knot : public JoinVisitor<Knot> {43  };44 45  void test() {46    Knot().Visit((struct Object1*) 0);47    Knot().Visit((struct Object2*) 0);48    Knot().Visit((struct Object3*) 0); // expected-error {{no matching member function for call}}49  }50}51 52// PR584753namespace test2 {54  namespace ns {55    void foo();56  }57 58  template <class T> void bar(T* ptr) {59    using ns::foo;60    foo();61  }62 63  template void bar(char *);64}65 66namespace test3 {67  template <typename T> struct t {68    struct s1 {69      T f1() const;70    };71    struct s2 : s1 {72      using s1::f1;73      T f1() const;74    };75  };76 77  void f2()78  {79    t<int>::s2 a;80    t<int>::s2 const & b = a;81    b.f1();82  }83}84 85namespace PR16936 {86  // Make sure both using decls are properly considered for87  // overload resolution.88  template<class> struct A {89    void access(int);90  };91  template<class> struct B {92    void access();93  };94  template<class CELL> struct X : public A<CELL>, public B<CELL> {95    using A<CELL>::access;96    using B<CELL>::access;97 98    void f() {99      access(0);100    }101  };102 103  void f() {104    X<int> x;105    x.f();106  }107}108 109namespace pr21923 {110template <typename> struct Base {111  int field;112  void method();113};114template <typename Scalar> struct Derived : Base<Scalar> {115  using Base<Scalar>::field;116  using Base<Scalar>::method;117  static void m_fn1() {118    // expected-error@+1 {{invalid use of member 'field' in static member function}}119    (void)field;120    // expected-error@+1 {{invalid use of member 'field' in static member function}}121    (void)&field;122    // expected-error@+1 {{call to non-static member function without an object argument}}123    (void)method;124    // expected-error@+1 {{must explicitly qualify name of member function when taking its address}}125    (void)&method;126    // expected-error@+1 {{call to non-static member function without an object argument}}127    method();128    (void)&Base<Scalar>::field;129    (void)&Base<Scalar>::method;130  }131#if __cplusplus >= 201103L132  // These usages are OK in C++11 due to the unevaluated context.133  enum { TheSize = sizeof(field) };134  typedef decltype(field) U;135#else136  // expected-error@+1 {{invalid use of non-static data member 'field'}}137  enum { TheSize = sizeof(field) };138#endif139};140 141#if __cplusplus < 201103L142// C++98 has an extra note for TheSize.143// expected-note@+2 {{requested here}}144#endif145template class Derived<int>; // expected-note {{requested here}}146 147// This is interesting because we form an UnresolvedLookupExpr in the static148// function template and an UnresolvedMemberExpr in the instance function149// template. As a result, we get slightly different behavior.150struct UnresolvedTemplateNames {151  template <typename> void maybe_static();152#if __cplusplus < 201103L153  // expected-warning@+2 {{default template arguments for a function template are a C++11 extension}}154#endif155  template <typename T, typename T::type = 0> static void maybe_static();156 157  template <typename T>158  void instance_method() { (void)maybe_static<T>(); }159  template <typename T>160  static void static_method() {161    // expected-error@+1 {{call to non-static member function without an object argument}}162    (void)maybe_static<T>();163  }164};165void force_instantiation(UnresolvedTemplateNames x) {166  x.instance_method<int>();167  UnresolvedTemplateNames::static_method<int>(); // expected-note {{requested here}}168}169} // pr21923170