diff options
author | Aleksei Sidorin <a.sidorin@samsung.com> | 2018-01-26 11:36:54 +0000 |
---|---|---|
committer | Aleksei Sidorin <a.sidorin@samsung.com> | 2018-01-26 11:36:54 +0000 |
commit | 8fc8510cb8dab5857e62870e976dfa7feca3fca7 (patch) | |
tree | 987fca5b298b2c15fa7be4579f9ea381df60058b /clang/test | |
parent | 24f0fa34c2e8d01ce97008f0f664016378079a92 (diff) | |
download | bcm5719-llvm-8fc8510cb8dab5857e62870e976dfa7feca3fca7.tar.gz bcm5719-llvm-8fc8510cb8dab5857e62870e976dfa7feca3fca7.zip |
[ASTImporter] Support LambdaExprs and improve template support
Also, a number of style and bug fixes was done:
* ASTImporterTest: added sanity check for source node
* ExternalASTMerger: better lookup for template specializations
* ASTImporter: don't add templated declarations into DeclContext
* ASTImporter: introduce a helper, ImportTemplateArgumentListInfo getting SourceLocations
* ASTImporter: proper set ParmVarDecls for imported FunctionProtoTypeLoc
Differential Revision: https://reviews.llvm.org/D42301
llvm-svn: 323519
Diffstat (limited to 'clang/test')
9 files changed, 73 insertions, 19 deletions
diff --git a/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp b/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp index 440b5abfc86..fb5b229e0ac 100644 --- a/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp +++ b/clang/test/ASTMerge/class-template/Inputs/class-template1.cpp @@ -1,5 +1,7 @@ template<typename T> -struct X0; +struct X0 { + T getValue(T arg) { return arg; } +}; template<int I> struct X1; @@ -26,6 +28,7 @@ extern X0<float> *x0r; template<> struct X0<char> { int member; + char getValue(char ch) { return static_cast<char>(member); } }; template<> diff --git a/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp b/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp index 6300301a4ff..b5d0add13f1 100644 --- a/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp +++ b/clang/test/ASTMerge/class-template/Inputs/class-template2.cpp @@ -1,5 +1,7 @@ template<class T> -struct X0; +struct X0 { + T getValue(T arg); +}; template<int I> struct X1; diff --git a/clang/test/ASTMerge/class-template/test.cpp b/clang/test/ASTMerge/class-template/test.cpp index 0ab5443db7f..7e25c5d6ccc 100644 --- a/clang/test/ASTMerge/class-template/test.cpp +++ b/clang/test/ASTMerge/class-template/test.cpp @@ -1,24 +1,28 @@ -// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/class-template1.cpp -// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/class-template2.cpp -// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s +// 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 -// CHECK: class-template1.cpp:7:14: error: non-type template parameter declared with incompatible types in different translation units ('int' vs. 'long') -// CHECK: class-template2.cpp:7:15: note: declared here with type 'long' +static_assert(sizeof(X0<char>().getValue(1)) == sizeof(char)); +static_assert(sizeof(X0<int>().getValue(1)) == sizeof(int)); -// CHECK: class-template1.cpp:10:14: error: template parameter has different kinds in different translation units -// CHECK: class-template2.cpp:10:10: note: template parameter declared here +// 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:16:23: error: non-type template parameter declared with incompatible types in different translation units ('long' vs. 'int') -// CHECK: class-template2.cpp:16:23: note: declared here with type 'int' +// 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:19:10: error: template parameter has different kinds in different translation units -// CHECK: class-template2.cpp:19: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-template2.cpp:25:20: error: external variable 'x0r' declared with incompatible types in different translation units ('X0<double> *' vs. 'X0<float> *') -// CHECK: class-template1.cpp:24:19: note: declared here with type 'X0<float> *' +// 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-template1.cpp:32:8: warning: type 'X0<wchar_t>' has incompatible definitions in different translation units -// CHECK: class-template1.cpp:33:7: note: field 'member' has type 'int' here -// CHECK: class-template2.cpp:34:9: note: field 'member' has type 'float' 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 diff --git a/clang/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp b/clang/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp index 2a33c35d9ea..6fdc33fb391 100644 --- a/clang/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp +++ b/clang/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp @@ -122,3 +122,20 @@ void useTemplateType() { const bool ExpressionTrait = __is_lvalue_expr(1); const unsigned ArrayRank = __array_rank(int[10][20]); const unsigned ArrayExtent = __array_extent(int[10][20], 1); + +constexpr int testLambdaAdd(int toAdd) { + const int Captured1 = 1, Captured2 = 2; + constexpr auto LambdaAdd = [Captured1, Captured2](int k) -> int { + return Captured1 + Captured2 + k; + }; + return LambdaAdd(toAdd); +} + +template<typename T> +struct TestLambdaTemplate { + T i, j; + TestLambdaTemplate(T i, const T &j) : i(i), j(j) {} + T testLambda(T k) { + return [this](T k) -> decltype(auto) { return i + j + k; }(k); + } +}; diff --git a/clang/test/ASTMerge/exprs-cpp/test.cpp b/clang/test/ASTMerge/exprs-cpp/test.cpp index 0535aa85330..c0b282ec028 100644 --- a/clang/test/ASTMerge/exprs-cpp/test.cpp +++ b/clang/test/ASTMerge/exprs-cpp/test.cpp @@ -30,6 +30,8 @@ static_assert(ExpressionTrait == false); static_assert(ArrayRank == 2); static_assert(ArrayExtent == 20); +static_assert(testLambdaAdd(3) == 6); + void testImport(int *x, const S1 &cs1, S1 &s1) { testNewThrowDelete(); testArrayElement(nullptr, 12); @@ -44,4 +46,5 @@ void testImport(int *x, const S1 &cs1, S1 &s1) { testDefaultArg(); testDefaultArgExpr(); useTemplateType(); + TestLambdaTemplate<int>(1, 2).testLambda(3); } diff --git a/clang/test/ASTMerge/function-cpp/Inputs/function-1.cpp b/clang/test/ASTMerge/function-cpp/Inputs/function-1.cpp new file mode 100644 index 00000000000..ee97a1a8a5d --- /dev/null +++ b/clang/test/ASTMerge/function-cpp/Inputs/function-1.cpp @@ -0,0 +1,8 @@ + +template<typename T> constexpr T add(T arg1, T arg2) { + return arg1 + arg2; +} + +template<> constexpr int add(int arg1, int arg2) { + return arg1 + arg2 + 2; +} diff --git a/clang/test/ASTMerge/function-cpp/test.cpp b/clang/test/ASTMerge/function-cpp/test.cpp new file mode 100644 index 00000000000..304ce3c634c --- /dev/null +++ b/clang/test/ASTMerge/function-cpp/test.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/function-1.cpp +// RUN: %clang_cc1 -std=c++1z -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck %s +// XFAIL: * + +static_assert(add(1, 2) == 5); + +// FIXME: support of templated function overload is still not implemented. +static_assert(add('\1', '\2') == 3); + +// CHECK-NOT: static_assert diff --git a/clang/test/Import/template-specialization/Inputs/T.cpp b/clang/test/Import/template-specialization/Inputs/T.cpp index b31e2439efe..7eea9582904 100644 --- a/clang/test/Import/template-specialization/Inputs/T.cpp +++ b/clang/test/Import/template-specialization/Inputs/T.cpp @@ -12,3 +12,7 @@ template <> struct A<bool> { int g; }; }; + + +template <typename T> constexpr int f() { return 0; } +template <> constexpr int f<int>() { return 4; } diff --git a/clang/test/Import/template-specialization/test.cpp b/clang/test/Import/template-specialization/test.cpp index 43996c53a77..30df8187602 100644 --- a/clang/test/Import/template-specialization/test.cpp +++ b/clang/test/Import/template-specialization/test.cpp @@ -1,7 +1,10 @@ // RUN: clang-import-test -import %S/Inputs/T.cpp -expression %s -// XFAIL: * + void expr() { A<int>::B b1; A<bool>::B b2; b1.f + b2.g; } + +static_assert(f<char>() == 0, ""); +static_assert(f<int>() == 4, ""); |