From 45074ec82d4fcfb90b753559b703a08dc1df8826 Mon Sep 17 00:00:00 2001 From: Hubert Tong Date: Fri, 29 Apr 2016 18:05:37 +0000 Subject: [PATCH] [Concepts] Pass requires-clause to ActOnTemplateParameterList; NFC Summary: Prepare to store requires-clause expression for access via TemplateParameterList. Reviewers: aaron.ballman, faisalv, rsmith Subscribers: cfe-commits, nwilson Differential Revision: http://reviews.llvm.org/D19220 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268081 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 3 ++- lib/Parse/ParseDecl.cpp | 2 +- lib/Parse/ParseDeclCXX.cpp | 2 +- lib/Parse/ParseTemplate.cpp | 19 +++++++++---------- lib/Sema/SemaTemplate.cpp | 9 ++++++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 3703500e76..db7c562c49 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -5647,7 +5647,8 @@ public: SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc); + SourceLocation RAngleLoc, + Expr *RequiresClause); /// \brief The context in which we are checking a template parameter list. enum TemplateParamListContext { diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index cbe3d91367..6b7ffb64fa 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2004,7 +2004,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( TemplateParameterLists FakedParamLists; FakedParamLists.push_back(Actions.ActOnTemplateParameterList( 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None, - LAngleLoc)); + LAngleLoc, nullptr)); ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(), FakedParamLists, D); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 6849eb9a6c..049e9ceae7 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1670,7 +1670,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // template specialization. FakedParamLists.push_back(Actions.ActOnTemplateParameterList( 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None, - LAngleLoc)); + LAngleLoc, nullptr)); TemplateParams = &FakedParamLists; } } diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 61da159ae0..6cf7b6d3dc 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -122,20 +122,15 @@ Parser::ParseTemplateDeclarationOrSpecialization(unsigned Context, return nullptr; } - ParamLists.push_back( - Actions.ActOnTemplateParameterList(CurTemplateDepthTracker.getDepth(), - ExportLoc, - TemplateLoc, LAngleLoc, - TemplateParams, RAngleLoc)); - + ExprResult OptionalRequiresClauseConstraintER; if (!TemplateParams.empty()) { isSpecialization = false; ++CurTemplateDepthTracker; if (TryConsumeToken(tok::kw_requires)) { - ExprResult ER = + OptionalRequiresClauseConstraintER = Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression()); - if (!ER.isUsable()) { + if (!OptionalRequiresClauseConstraintER.isUsable()) { // Skip until the semi-colon or a '}'. SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); TryConsumeToken(tok::semi); @@ -145,6 +140,10 @@ Parser::ParseTemplateDeclarationOrSpecialization(unsigned Context, } else { LastParamListWasEmpty = true; } + + ParamLists.push_back(Actions.ActOnTemplateParameterList( + CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc, + TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.get())); } while (Tok.isOneOf(tok::kw_export, tok::kw_template)); unsigned NewFlags = getCurScope()->getFlags() & ~Scope::TemplateParamScope; @@ -287,7 +286,7 @@ Parser::ParseSingleDeclarationAfterTemplate( TemplateParameterLists FakedParamLists; FakedParamLists.push_back(Actions.ActOnTemplateParameterList( 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None, - LAngleLoc)); + LAngleLoc, nullptr)); return ParseFunctionDefinition( DeclaratorInfo, ParsedTemplateInfo(&FakedParamLists, @@ -638,7 +637,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { Actions.ActOnTemplateParameterList(Depth, SourceLocation(), TemplateLoc, LAngleLoc, TemplateParams, - RAngleLoc); + RAngleLoc, nullptr); // Grab a default argument (if available). // Per C++0x [basic.scope.pdecl]p9, we parse the default argument before diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 3833e2c3f0..9d3bf1c160 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -817,18 +817,21 @@ Decl *Sema::ActOnTemplateTemplateParameter(Scope* S, return Param; } -/// ActOnTemplateParameterList - Builds a TemplateParameterList that -/// contains the template parameters in Params/NumParams. +/// ActOnTemplateParameterList - Builds a TemplateParameterList, optionally +/// constrained by RequiresClause, that contains the template parameters in +/// Params. TemplateParameterList * Sema::ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef Params, - SourceLocation RAngleLoc) { + SourceLocation RAngleLoc, + Expr *RequiresClause) { if (ExportLoc.isValid()) Diag(ExportLoc, diag::warn_template_export_unsupported); + // FIXME: store RequiresClause return TemplateParameterList::Create( Context, TemplateLoc, LAngleLoc, llvm::makeArrayRef((NamedDecl *const *)Params.data(), Params.size()), -- 2.40.0