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