template-id-printing.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // RUN: %clang_cc1 -fsyntax-only -ast-print %s | FileCheck %s
  2. namespace N {
  3. template<typename T, typename U> void f(U);
  4. template<int> void f();
  5. }
  6. void g() {
  7. // CHECK: N::f<int>(3.14
  8. N::f<int>(3.14);
  9. // CHECK: N::f<double>
  10. void (*fp)(int) = N::f<double>;
  11. }
  12. // (NNS qualified) DeclRefExpr.
  13. namespace DRE {
  14. template <typename T>
  15. void foo();
  16. void test() {
  17. // CHECK: DRE::foo<int>;
  18. DRE::foo<int>;
  19. // CHECK: DRE::template foo<int>;
  20. DRE::template foo<int>;
  21. // CHECK: DRE::foo<int>();
  22. DRE::foo<int>();
  23. // CHECK: DRE::template foo<int>();
  24. DRE::template foo<int>();
  25. }
  26. } // namespace DRE
  27. // MemberExpr.
  28. namespace ME {
  29. struct S {
  30. template <typename T>
  31. void mem();
  32. };
  33. void test() {
  34. S s;
  35. // CHECK: s.mem<int>();
  36. s.mem<int>();
  37. // CHECK: s.template mem<int>();
  38. s.template mem<int>();
  39. }
  40. } // namespace ME
  41. // UnresolvedLookupExpr.
  42. namespace ULE {
  43. template <typename T>
  44. int foo();
  45. template <typename T>
  46. void test() {
  47. // CHECK: ULE::foo<T>;
  48. ULE::foo<T>;
  49. // CHECK: ULE::template foo<T>;
  50. ULE::template foo<T>;
  51. }
  52. } // namespace ULE
  53. // UnresolvedMemberExpr.
  54. namespace UME {
  55. struct S {
  56. template <typename T>
  57. void mem();
  58. };
  59. template <typename U>
  60. void test() {
  61. S s;
  62. // CHECK: s.mem<U>();
  63. s.mem<U>();
  64. // CHECK: s.template mem<U>();
  65. s.template mem<U>();
  66. }
  67. } // namespace UME
  68. // DependentScopeDeclRefExpr.
  69. namespace DSDRE {
  70. template <typename T>
  71. struct S;
  72. template <typename T>
  73. void test() {
  74. // CHECK: S<T>::foo;
  75. S<T>::foo;
  76. // CHECK: S<T>::template foo;
  77. S<T>::template foo;
  78. // CHECK: S<T>::template foo<>;
  79. S<T>::template foo<>;
  80. // CHECK: S<T>::template foo<T>;
  81. S<T>::template foo<T>;
  82. }
  83. } // namespace DSDRE
  84. // DependentScopeMemberExpr.
  85. namespace DSME {
  86. template <typename T>
  87. struct S;
  88. template <typename T>
  89. void test() {
  90. S<T> s;
  91. // CHECK: s.foo;
  92. s.foo;
  93. // CHECK: s.template foo;
  94. s.template foo;
  95. // CHECK: s.template foo<>;
  96. s.template foo<>;
  97. // CHECK: s.template foo<T>;
  98. s.template foo<T>;
  99. }
  100. } // namespace DSME
  101. namespace DSDRE_withImplicitTemplateArgs {
  102. template <typename T> void foo() {
  103. // CHECK: T::template bar();
  104. T::template bar();
  105. }
  106. } // namespace DSDRE_withImplicitTemplateArgs