Output generated by option -ast-print looks like C/C++ code, and it really is for plain C. For C++ the produced output was not valid C++ code, but the differences were small. With this change the output is fixed and can be compiled. Tests are changed so that output produced by -ast-print is compiled again with the same flags and both outputs are compared. Option -ast-print is extensively used in clang tests but it itself was tested poorly, existing tests only checked that compiler did not crash. There are unit tests in file DeclPrinterTest.cpp, but they test only terse output mode. Differential Revision: https://reviews.llvm.org/D26452 llvm-svn: 286439
64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
// RUN: %clang_cc1 -ast-print %s > %t
|
|
// RUN: FileCheck < %t %s -check-prefix=CHECK1
|
|
// RUN: FileCheck < %t %s -check-prefix=CHECK2
|
|
// RUN: %clang_cc1 -ast-dump %s | FileCheck --check-prefix=DUMP %s
|
|
|
|
template <int X, typename Y, int Z = 5>
|
|
struct foo {
|
|
int constant;
|
|
foo() {}
|
|
Y getSum() { return Y(X + Z); }
|
|
};
|
|
|
|
template <int A, typename B>
|
|
B bar() {
|
|
return B(A);
|
|
}
|
|
|
|
void baz() {
|
|
int x = bar<5, int>();
|
|
int y = foo<5, int>().getSum();
|
|
double z = foo<2, double, 3>().getSum();
|
|
}
|
|
|
|
// Template definition - foo
|
|
// CHECK1: template <int X, typename Y, int Z = 5> struct foo {
|
|
// CHECK2: template <int X, typename Y, int Z = 5> struct foo {
|
|
|
|
// Template instantiation - foo
|
|
// Since the order of instantiation may vary during runs, run FileCheck twice
|
|
// to make sure each instantiation is in the correct spot.
|
|
// CHECK1: template<> struct foo<5, int, 5> {
|
|
// CHECK2: template<> struct foo<2, double, 3> {
|
|
|
|
// Template definition - bar
|
|
// CHECK1: template <int A, typename B> B bar()
|
|
// CHECK2: template <int A, typename B> B bar()
|
|
|
|
// Template instantiation - bar
|
|
// CHECK1: template<> int bar<5, int>()
|
|
// CHECK2: template<> int bar<5, int>()
|
|
|
|
// CHECK1-LABEL: template <typename ...T> struct A {
|
|
// CHECK1-NEXT: template <T ...x[3]> struct B {
|
|
template <typename ...T> struct A {
|
|
template <T ...x[3]> struct B {};
|
|
};
|
|
|
|
// CHECK1-LABEL: template <typename ...T> void f(T ...[3]) {
|
|
// CHECK1-NEXT: A<T [3]...> a;
|
|
template <typename ...T> void f(T ...[3]) {
|
|
A<T [3]...> a;
|
|
}
|
|
|
|
namespace test2 {
|
|
void func(int);
|
|
void func(float);
|
|
template<typename T>
|
|
void tmpl() {
|
|
func(T());
|
|
}
|
|
|
|
// DUMP: UnresolvedLookupExpr {{.*}} <col:3> '<overloaded function type>' lvalue (ADL) = 'func'
|
|
}
|