instantiate-member-expr.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic
  2. template<typename T>
  3. struct S {
  4. S() { }
  5. };
  6. template<typename T>
  7. struct vector {
  8. void push_back(const T&) { int a[sizeof(T) ? -1: -1]; } // expected-error {{array with a negative size}}
  9. };
  10. class ExprEngine {
  11. public:
  12. typedef vector<S<void *> >CheckersOrdered;
  13. CheckersOrdered Checkers;
  14. template <typename CHECKER>
  15. void registerCheck(CHECKER *check) {
  16. Checkers.push_back(S<void *>()); // expected-note {{in instantiation of member function 'vector<S<void *> >::push_back' requested here}}
  17. }
  18. };
  19. class RetainReleaseChecker { };
  20. void f(ExprEngine& Eng) {
  21. Eng.registerCheck(new RetainReleaseChecker); // expected-note {{in instantiation of function template specialization 'ExprEngine::registerCheck<RetainReleaseChecker>' requested here}}
  22. }
  23. // PR 5838
  24. namespace test1 {
  25. template<typename T> struct A {
  26. int a;
  27. };
  28. template<typename T> struct B : A<float>, A<T> {
  29. void f() {
  30. a = 0; // should not be ambiguous
  31. }
  32. };
  33. template struct B<int>;
  34. struct O {
  35. int a;
  36. template<typename T> struct B : A<T> {
  37. void f() {
  38. a = 0; // expected-error {{'test1::O::a' is not a member of class 'test1::O::B<int>'}}
  39. }
  40. };
  41. };
  42. template struct O::B<int>; // expected-note {{in instantiation}}
  43. }
  44. // PR7248
  45. namespace test2 {
  46. template <class T> struct A {
  47. void foo() {
  48. T::bar(); // expected-error {{type 'int' cannot}}
  49. }
  50. };
  51. template <class T> class B {
  52. void foo(A<T> a) {
  53. a.test2::template A<T>::foo(); // expected-note {{in instantiation}}
  54. }
  55. };
  56. template class B<int>;
  57. }
  58. namespace PR14124 {
  59. template<typename T> struct S {
  60. int value;
  61. };
  62. template<typename T> void f() { S<T>::value; } // expected-error {{invalid use of non-static data member 'value'}}
  63. template void f<int>(); // expected-note {{in instantiation of}}
  64. struct List { List *next; };
  65. template<typename T, T *(T::*p) = &T::next> struct A {};
  66. A<List> a; // ok
  67. void operator&(struct Whatever);
  68. template<typename T, T *(T::*p) = &T::next> struct B {};
  69. B<List> b; // still ok
  70. }