diff options
Diffstat (limited to 'clang/test/ASTMerge/class-template')
3 files changed, 104 insertions, 0 deletions
diff --git a/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp b/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp new file mode 100644 index 00000000000..fb5b229e0ac --- /dev/null +++ b/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp @@ -0,0 +1,37 @@ +template<typename T> +struct X0 { + T getValue(T arg) { return arg; } +}; + +template<int I> +struct X1; + +template<int I> +struct X2; + +template<int I> +struct X3; + +template<template<int I> class> +struct X4; + +template<template<long> class> +struct X5; + +template<typename> +struct X6; + +extern X0<int> *x0i; +extern X0<long> *x0l; +extern X0<float> *x0r; + +template<> +struct X0<char> { + int member; + char getValue(char ch) { return static_cast<char>(member); } +}; + +template<> +struct X0<wchar_t> { + int member; +}; diff --git a/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp b/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp new file mode 100644 index 00000000000..b5d0add13f1 --- /dev/null +++ b/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp @@ -0,0 +1,37 @@ +template<class T> +struct X0 { + T getValue(T arg); +}; + +template<int I> +struct X1; + +template<long I> +struct X2; + +template<typename> +struct X3; + +template<template<int I> class> +struct X4; + +template<template<int I> class> +struct X5; + +template<template<int I> class> +struct X6; + +typedef int Integer; +extern X0<Integer> *x0i; +extern X0<float> *x0f; +extern X0<double> *x0r; + +template<> +struct X0<char> { + int member; +}; + +template<> +struct X0<wchar_t> { + float member; +}; diff --git a/clang/test/ASTMerge/class-template/test.cpp b/clang/test/ASTMerge/class-template/test.cpp new file mode 100644 index 00000000000..f2ac4c5a631 --- /dev/null +++ b/clang/test/ASTMerge/class-template/test.cpp @@ -0,0 +1,30 @@ +// FIXME: Errors are now warnings. +// XFAIL: * +// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/class-template1.cpp +// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.2.ast %S/Inputs/class-template2.cpp +// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +static_assert(sizeof(X0<char>().getValue(1)) == sizeof(char)); +static_assert(sizeof(X0<int>().getValue(1)) == sizeof(int)); + +// CHECK: class-template1.cpp:9:14: error: non-type template parameter declared with incompatible types in different translation units ('int' vs. 'long') +// CHECK: class-template2.cpp:9:15: note: declared here with type 'long' + +// CHECK: class-template1.cpp:12:14: error: template parameter has different kinds in different translation units +// CHECK: class-template2.cpp:12:10: note: template parameter declared here + +// CHECK: class-template1.cpp:18:23: error: non-type template parameter declared with incompatible types in different translation units ('long' vs. 'int') +// CHECK: class-template2.cpp:18:23: note: declared here with type 'int' + +// CHECK: class-template1.cpp:21:10: error: template parameter has different kinds in different translation units +// CHECK: class-template2.cpp:21:10: note: template parameter declared here + +// CHECK: class-template2.cpp:27:20: error: external variable 'x0r' declared with incompatible types in different translation units ('X0<double> *' vs. 'X0<float> *') +// CHECK: class-template1.cpp:26:19: note: declared here with type 'X0<float> *' + +// CHECK: class-template1.cpp:35:8: warning: type 'X0<wchar_t>' has incompatible definitions in different translation units +// CHECK: class-template1.cpp:36:7: note: field 'member' has type 'int' here +// CHECK: class-template2.cpp:36:9: note: field 'member' has type 'float' here + +// CHECK: 1 warning and 5 errors generated. +// CHECK-NOT: static_assert |