Richard Trieu | 7efa0e0 | 2011-07-28 20:30:10 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -ast-dump %s > %t |
| 2 | // RUN: FileCheck < %t %s -check-prefix=CHECK1 |
| 3 | // RUN: FileCheck < %t %s -check-prefix=CHECK2 |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 4 | |
| 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 | |
| 12 | template <int A, typename B> |
| 13 | B bar() { |
| 14 | return B(A); |
| 15 | } |
| 16 | |
| 17 | void baz() { |
| 18 | int x = bar<5, int>(); |
| 19 | int y = foo<5, int>().getSum(); |
| 20 | double z = foo<2, double, 3>().getSum(); |
| 21 | } |
| 22 | |
| 23 | // Template instantiation - foo |
Richard Trieu | 7efa0e0 | 2011-07-28 20:30:10 +0000 | [diff] [blame] | 24 | // Since the order of instantiation may vary during runs, run FileCheck twice |
| 25 | // to make sure each instantiation is in the correct spot. |
| 26 | // CHECK1: template <int X = 5, typename Y = int, int Z = 5> struct foo { |
| 27 | // CHECK2: template <int X = 2, typename Y = double, int Z = 3> struct foo { |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 28 | |
| 29 | // Template definition - foo |
Richard Trieu | 7efa0e0 | 2011-07-28 20:30:10 +0000 | [diff] [blame] | 30 | // CHECK1: template <int X, typename Y, int Z = (IntegerLiteral {{.*}} 'int' 5) |
| 31 | // CHECK2: template <int X, typename Y, int Z = (IntegerLiteral {{.*}} 'int' 5) |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 32 | |
| 33 | // Template instantiation - bar |
Richard Trieu | 7efa0e0 | 2011-07-28 20:30:10 +0000 | [diff] [blame] | 34 | // CHECK1: template <int A = 5, typename B = int> int bar() |
| 35 | // CHECK2: template <int A = 5, typename B = int> int bar() |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 36 | |
| 37 | // Template definition - bar |
Richard Trieu | 7efa0e0 | 2011-07-28 20:30:10 +0000 | [diff] [blame] | 38 | // CHECK1: template <int A, typename B> B bar() |
| 39 | // CHECK2: template <int A, typename B> B bar() |