member-function-template.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. struct X {
  3. template<typename T> T& f0(T);
  4. void g0(int i, double d) {
  5. int &ir = f0(i);
  6. double &dr = f0(d);
  7. }
  8. template<typename T> T& f1(T);
  9. template<typename T, typename U> U& f1(T, U);
  10. void g1(int i, double d) {
  11. int &ir1 = f1(i);
  12. int &ir2 = f1(d, i);
  13. int &ir3 = f1(i, i);
  14. }
  15. };
  16. void test_X_f0(X x, int i, float f) {
  17. int &ir = x.f0(i);
  18. float &fr = x.f0(f);
  19. }
  20. void test_X_f1(X x, int i, float f) {
  21. int &ir1 = x.f1(i);
  22. int &ir2 = x.f1(f, i);
  23. int &ir3 = x.f1(i, i);
  24. }
  25. void test_X_f0_address() {
  26. int& (X::*pm1)(int) = &X::f0;
  27. float& (X::*pm2)(float) = &X::f0;
  28. }
  29. void test_X_f1_address() {
  30. int& (X::*pm1)(int) = &X::f1;
  31. float& (X::*pm2)(float) = &X::f1;
  32. int& (X::*pm3)(float, int) = &X::f1;
  33. }
  34. void test_X_f0_explicit(X x, int i, long l) {
  35. int &ir1 = x.f0<int>(i);
  36. int &ir2 = x.f0<>(i);
  37. long &il1 = x.f0<long>(i);
  38. }
  39. // PR4608
  40. class A { template <class x> x a(x z) { return z+y; } int y; };
  41. // PR5419
  42. struct Functor {
  43. template <typename T>
  44. bool operator()(const T& v) const {
  45. return true;
  46. }
  47. };
  48. void test_Functor(Functor f) {
  49. f(1);
  50. }
  51. // Instantiation on ->
  52. template<typename T>
  53. struct X1 {
  54. template<typename U> U& get();
  55. };
  56. template<typename T> struct X2; // expected-note{{here}}
  57. void test_incomplete_access(X1<int> *x1, X2<int> *x2) {
  58. float &fr = x1->get<float>();
  59. (void)x2->get<float>(); // expected-error{{implicit instantiation of undefined template}}
  60. }
  61. // Instantiation of template template parameters in a member function
  62. // template.
  63. namespace TTP {
  64. template<int Dim> struct X {
  65. template<template<class> class M, class T> void f(const M<T>&);
  66. };
  67. template<typename T> struct Y { };
  68. void test_f(X<3> x, Y<int> y) { x.f(y); }
  69. }
  70. namespace PR7387 {
  71. template <typename T> struct X {};
  72. template <typename T1> struct S {
  73. template <template <typename> class TC> void foo(const TC<T1>& arg);
  74. };
  75. template <typename T1> template <template <typename> class TC>
  76. void S<T1>::foo(const TC<T1>& arg) {}
  77. void test(const X<int>& x) {
  78. S<int> s;
  79. s.foo(x);
  80. }
  81. }