summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-08-22 00:34:47 +0000
committerDouglas Gregor <dgregor@apple.com>2009-08-22 00:34:47 +0000
commitd83d04041f64a2c89123d227fa8003b482391279 (patch)
treecff3c814385b448dfc048774b1ba787dfd188f0b /lib
parentc141086bff9c2809aa46efdc5ce66756430f3470 (diff)
Implement delayed parsing for member function templates. Fixes PR4608.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79709 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Parse/ParseCXXInlineMethods.cpp15
-rw-r--r--lib/Parse/ParseDeclCXX.cpp1
-rw-r--r--lib/Sema/SemaDecl.cpp20
3 files changed, 30 insertions, 6 deletions
diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp
index 80feff42d7..f967c7a69d 100644
--- a/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/lib/Parse/ParseCXXInlineMethods.cpp
@@ -44,6 +44,8 @@ Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D,
// Consume the tokens and store them for later parsing.
getCurrentClass().MethodDefs.push_back(LexedMethod(FnD));
+ getCurrentClass().MethodDefs.back().TemplateScope
+ = CurScope->isTemplateParamScope();
CachedTokens &Toks = getCurrentClass().MethodDefs.back().Toks;
tok::TokenKind kind = Tok.getKind();
@@ -99,9 +101,11 @@ void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {
for (; !Class.MethodDecls.empty(); Class.MethodDecls.pop_front()) {
LateParsedMethodDeclaration &LM = Class.MethodDecls.front();
- // FIXME: For member function templates, we'll need to introduce a
- // scope for the template parameters.
-
+ // If this is a member template, introduce the template parameter scope.
+ ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
+ if (LM.TemplateScope)
+ Actions.ActOnReenterTemplateScope(CurScope, LM.Method);
+
// Start the delayed C++ method declaration
Actions.ActOnStartDelayedCXXMethodDeclaration(CurScope, LM.Method);
@@ -161,6 +165,11 @@ void Parser::ParseLexedMethodDefs(ParsingClass &Class) {
for (; !Class.MethodDefs.empty(); Class.MethodDefs.pop_front()) {
LexedMethod &LM = Class.MethodDefs.front();
+ // If this is a member template, introduce the template parameter scope.
+ ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
+ if (LM.TemplateScope)
+ Actions.ActOnReenterTemplateScope(CurScope, LM.D);
+
assert(!LM.Toks.empty() && "Empty body!");
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index bce9ee0d82..af4f83a505 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -861,6 +861,7 @@ void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo,
getCurrentClass().MethodDecls.push_back(
LateParsedMethodDeclaration(ThisDecl));
LateMethod = &getCurrentClass().MethodDecls.back();
+ LateMethod->TemplateScope = CurScope->isTemplateParamScope();
// Add all of the parameters prior to this one (they don't
// have default arguments).
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 4017772083..6668aeaac5 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3526,7 +3526,13 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope,
Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) {
if (!D)
return D;
- FunctionDecl *FD = cast<FunctionDecl>(D.getAs<Decl>());
+ FunctionDecl *FD = 0;
+
+ if (FunctionTemplateDecl *FunTmpl
+ = dyn_cast<FunctionTemplateDecl>(D.getAs<Decl>()))
+ FD = FunTmpl->getTemplatedDecl();
+ else
+ FD = cast<FunctionDecl>(D.getAs<Decl>());
CurFunctionNeedsScopeChecking = false;
@@ -3624,7 +3630,15 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg,
bool IsInstantiation) {
Decl *dcl = D.getAs<Decl>();
Stmt *Body = BodyArg.takeAs<Stmt>();
- if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(dcl)) {
+
+ FunctionDecl *FD = 0;
+ FunctionTemplateDecl *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(dcl);
+ if (FunTmpl)
+ FD = FunTmpl->getTemplatedDecl();
+ else
+ FD = dyn_cast_or_null<FunctionDecl>(dcl);
+
+ if (FD) {
FD->setBody(Body);
if (FD->isMain(Context))
// C and C++ allow for main to automagically return 0.
@@ -3711,7 +3725,7 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg,
// C++ constructors that have function-try-blocks can't have return
// statements in the handlers of that block. (C++ [except.handle]p14)
// Verify this.
- if (isa<CXXConstructorDecl>(dcl) && isa<CXXTryStmt>(Body))
+ if (FD && isa<CXXConstructorDecl>(FD) && isa<CXXTryStmt>(Body))
DiagnoseReturnInConstructorExceptionHandler(cast<CXXTryStmt>(Body));
if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(dcl))