instantiation-default-1.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T, typename U = const T> struct Def1;
  3. template<> struct Def1<int> {
  4. void foo();
  5. };
  6. template<> struct Def1<const int> { // expected-note{{previous definition is here}}
  7. void bar();
  8. };
  9. template<> struct Def1<int&> {
  10. void wibble();
  11. };
  12. void test_Def1(Def1<int, const int> *d1, Def1<const int, const int> *d2,
  13. Def1<int&, int&> *d3) {
  14. d1->foo();
  15. d2->bar();
  16. d3->wibble();
  17. }
  18. template<typename T, // FIXME: bad error message below, needs better location info
  19. typename T2 = const T*> // expected-error{{'T2' declared as a pointer to a reference}}
  20. struct Def2;
  21. template<> struct Def2<int> {
  22. void foo();
  23. };
  24. void test_Def2(Def2<int, int const*> *d2) {
  25. d2->foo();
  26. }
  27. typedef int& int_ref_t;
  28. Def2<int_ref_t> *d2; // expected-note{{in instantiation of default argument for 'Def2<int &>' required here}}
  29. template<> struct Def1<const int, const int> { }; // expected-error{{redefinition of 'Def1<const int>'}}
  30. template<typename T, typename T2 = T&> struct Def3;
  31. template<> struct Def3<int> {
  32. void foo();
  33. };
  34. template<> struct Def3<int&> {
  35. void bar();
  36. };
  37. void test_Def3(Def3<int, int&> *d3a, Def3<int&, int&> *d3b) {
  38. d3a->foo();
  39. d3b->bar();
  40. }
  41. template<typename T, typename T2 = T[]> struct Def4;
  42. template<> struct Def4<int> {
  43. void foo();
  44. };
  45. void test_Def4(Def4<int, int[]> *d4a) {
  46. d4a->foo();
  47. }
  48. template<typename T, typename T2 = T const[12]> struct Def5;
  49. template<> struct Def5<int> {
  50. void foo();
  51. };
  52. template<> struct Def5<int, int const[13]> {
  53. void bar();
  54. };
  55. void test_Def5(Def5<int, const int[12]> *d5a, Def5<int, const int[13]> *d5b) {
  56. d5a->foo();
  57. d5b->bar();
  58. }
  59. template<typename R, typename Arg1, typename Arg2 = Arg1,
  60. typename FuncType = R (*)(Arg1, Arg2)>
  61. struct Def6;
  62. template<> struct Def6<int, float> {
  63. void foo();
  64. };
  65. template<> struct Def6<bool, int[5], float(double, double)> {
  66. void bar();
  67. };
  68. bool test_Def6(Def6<int, float, float> *d6a,
  69. Def6<int, float, float, int (*)(float, float)> *d6b,
  70. Def6<bool, int[5], float(double, double),
  71. bool(*)(int*, float(*)(double, double))> *d6c) {
  72. d6a->foo();
  73. d6b->foo();
  74. d6c->bar();
  75. return d6a == d6b;
  76. }