LambdaTemplateParams.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===- unittest/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp -===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "TestVisitor.h"
  10. using namespace clang;
  11. namespace {
  12. // Matches (optional) explicit template parameters.
  13. class LambdaTemplateParametersVisitor
  14. : public ExpectedLocationVisitor<LambdaTemplateParametersVisitor> {
  15. public:
  16. bool shouldVisitImplicitCode() const { return false; }
  17. bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
  18. EXPECT_FALSE(D->isImplicit());
  19. Match(D->getName(), D->getBeginLoc());
  20. return true;
  21. }
  22. bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
  23. EXPECT_FALSE(D->isImplicit());
  24. Match(D->getName(), D->getBeginLoc());
  25. return true;
  26. }
  27. bool VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
  28. EXPECT_FALSE(D->isImplicit());
  29. Match(D->getName(), D->getBeginLoc());
  30. return true;
  31. }
  32. };
  33. TEST(RecursiveASTVisitor, VisitsLambdaExplicitTemplateParameters) {
  34. LambdaTemplateParametersVisitor Visitor;
  35. Visitor.ExpectMatch("T", 2, 15);
  36. Visitor.ExpectMatch("I", 2, 24);
  37. Visitor.ExpectMatch("TT", 2, 31);
  38. EXPECT_TRUE(Visitor.runOver(
  39. "void f() { \n"
  40. " auto l = []<class T, int I, template<class> class TT>(auto p) { }; \n"
  41. "}",
  42. LambdaTemplateParametersVisitor::Lang_CXX2a));
  43. }
  44. } // end anonymous namespace