diff options
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/AST/StmtPrinterTest.cpp | 37 | ||||
-rw-r--r-- | clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp | 53 |
2 files changed, 90 insertions, 0 deletions
diff --git a/clang/unittests/AST/StmtPrinterTest.cpp b/clang/unittests/AST/StmtPrinterTest.cpp index abd56c2875e..0d383d547a2 100644 --- a/clang/unittests/AST/StmtPrinterTest.cpp +++ b/clang/unittests/AST/StmtPrinterTest.cpp @@ -157,6 +157,43 @@ TEST(StmtPrinter, TestCXXConversionDeclExplicit) { // WRONG; Should be: (a & b).operator void *() } +TEST(StmtPrinter, TestCXXLamda) { + ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11, + "void A() {" + " auto l = [] { };" + "}", + lambdaExpr(anything()).bind("id"), + "[] {\n" + "}")); + + ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX11, + "void A() {" + " int a = 0, b = 1;" + " auto l = [a,b](int c, float d) { };" + "}", + lambdaExpr(anything()).bind("id"), + "[a, b](int c, float d) {\n" + "}")); + + ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX14, + "void A() {" + " auto l = [](auto a, int b, auto c, int, auto) { };" + "}", + lambdaExpr(anything()).bind("id"), + "[](auto a, int b, auto c, int, auto) {\n" + "}")); + + ASSERT_TRUE(PrintedStmtCXXMatches(StdVer::CXX2a, + "void A() {" + " auto l = []<typename T1, class T2, int I," + " template<class, typename> class T3>" + " (int a, auto, int, auto d) { };" + "}", + lambdaExpr(anything()).bind("id"), + "[]<typename T1, class T2, int I, template <class, typename> class T3>(int a, auto, int, auto d) {\n" + "}")); +} + TEST(StmtPrinter, TestNoImplicitBases) { const char *CPPSource = R"( class A { diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp new file mode 100644 index 00000000000..d0e4fb733e8 --- /dev/null +++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp @@ -0,0 +1,53 @@ +//===- unittest/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "TestVisitor.h" + +using namespace clang; + +namespace { + +// Matches (optional) explicit template parameters. +class LambdaTemplateParametersVisitor + : public ExpectedLocationVisitor<LambdaTemplateParametersVisitor> { +public: + bool shouldVisitImplicitCode() const { return false; } + + bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { + EXPECT_FALSE(D->isImplicit()); + Match(D->getName(), D->getLocStart()); + return true; + } + + bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { + EXPECT_FALSE(D->isImplicit()); + Match(D->getName(), D->getLocStart()); + return true; + } + + bool VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { + EXPECT_FALSE(D->isImplicit()); + Match(D->getName(), D->getLocStart()); + return true; + } +}; + +TEST(RecursiveASTVisitor, VisitsLambdaExplicitTemplateParameters) { + LambdaTemplateParametersVisitor Visitor; + Visitor.ExpectMatch("T", 2, 15); + Visitor.ExpectMatch("I", 2, 24); + Visitor.ExpectMatch("TT", 2, 31); + EXPECT_TRUE(Visitor.runOver( + "void f() { \n" + " auto l = []<class T, int I, template<class> class TT>(auto p) { }; \n" + "}", + LambdaTemplateParametersVisitor::Lang_CXX2a)); +} + +} // end anonymous namespace |