ast-dump-templates.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // RUN: %clang_cc1 -ast-print %s > %t
  2. // RUN: FileCheck < %t %s -check-prefix=CHECK1
  3. // RUN: FileCheck < %t %s -check-prefix=CHECK2
  4. // RUN: %clang_cc1 -ast-dump %s | FileCheck --check-prefix=DUMP %s
  5. template <int X, typename Y, int Z = 5>
  6. struct foo {
  7. int constant;
  8. foo() {}
  9. Y getSum() { return Y(X + Z); }
  10. };
  11. template <int A, typename B>
  12. B bar() {
  13. return B(A);
  14. }
  15. void baz() {
  16. int x = bar<5, int>();
  17. int y = foo<5, int>().getSum();
  18. double z = foo<2, double, 3>().getSum();
  19. }
  20. // Template instantiation - foo
  21. // Since the order of instantiation may vary during runs, run FileCheck twice
  22. // to make sure each instantiation is in the correct spot.
  23. // CHECK1: template <int X = 5, typename Y = int, int Z = 5> struct foo {
  24. // CHECK2: template <int X = 2, typename Y = double, int Z = 3> struct foo {
  25. // Template definition - foo
  26. // CHECK1: template <int X, typename Y, int Z = 5> struct foo {
  27. // CHECK2: template <int X, typename Y, int Z = 5> struct foo {
  28. // Template instantiation - bar
  29. // CHECK1: template <int A = 5, typename B = int> int bar()
  30. // CHECK2: template <int A = 5, typename B = int> int bar()
  31. // Template definition - bar
  32. // CHECK1: template <int A, typename B> B bar()
  33. // CHECK2: template <int A, typename B> B bar()
  34. // CHECK1-LABEL: template <typename ...T> struct A {
  35. // CHECK1-NEXT: template <T ...x[3]> struct B {
  36. template <typename ...T> struct A {
  37. template <T ...x[3]> struct B {};
  38. };
  39. // CHECK1-LABEL: template <typename ...T> void f(T ...[3]) {
  40. // CHECK1-NEXT: A<T [3]...> a;
  41. template <typename ...T> void f(T ...[3]) {
  42. A<T [3]...> a;
  43. }
  44. namespace test2 {
  45. void func(int);
  46. void func(float);
  47. template<typename T>
  48. void tmpl() {
  49. func(T());
  50. }
  51. // DUMP: UnresolvedLookupExpr {{.*}} <col:3> '<overloaded function type>' lvalue (ADL) = 'func'
  52. }