[cfe-commits] r71869 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-function-1.cpp
Douglas Gregor
dgregor at apple.com
Fri May 15 10:59:07 PDT 2009
Author: dgregor
Date: Fri May 15 12:59:04 2009
New Revision: 71869
URL: http://llvm.org/viewvc/llvm-project?rev=71869&view=rev
Log:
Call ActOnStartOfFunctionDecl/ActOnFinishFunctionBody when
instantiating the definition of a function from a template.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=71869&r1=71868&r2=71869&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri May 15 12:59:04 2009
@@ -414,6 +414,8 @@
virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclPtrTy D);
virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body);
+ DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body,
+ bool IsInstantiation);
void DiagnoseInvalidJumps(Stmt *Body);
virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=71869&r1=71868&r2=71869&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May 15 12:59:04 2009
@@ -3002,7 +3002,8 @@
Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;
}
- PushDeclContext(FnBodyScope, FD);
+ if (FnBodyScope)
+ PushDeclContext(FnBodyScope, FD);
// Check the validity of our function parameters
CheckParmsForFunctionDef(FD);
@@ -3013,7 +3014,7 @@
Param->setOwningFunction(FD);
// If this has an identifier, add it to the scope stack.
- if (Param->getIdentifier())
+ if (Param->getIdentifier() && FnBodyScope)
PushOnScopeChains(Param, FnBodyScope);
}
@@ -3039,8 +3040,12 @@
return DeclPtrTy::make(FD);
}
-
Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg) {
+ return ActOnFinishFunctionBody(D, move(BodyArg), false);
+}
+
+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)) {
@@ -3053,7 +3058,9 @@
Body->Destroy(Context);
return DeclPtrTy();
}
- PopDeclContext();
+ if (!IsInstantiation)
+ PopDeclContext();
+
// Verify and clean out per-function state.
assert(&getLabelMap() == &FunctionLabelMap && "Didn't pop block right?");
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=71869&r1=71868&r2=71869&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri May 15 12:59:04 2009
@@ -2332,14 +2332,14 @@
//
// This check comes when we actually try to perform the
// instantiation.
- if (SpecializationRequiresInstantiation &&
- InstantiateClassTemplateSpecialization(Specialization, true))
- return true;
+ if (SpecializationRequiresInstantiation)
+ InstantiateClassTemplateSpecialization(Specialization, true);
+ else {
+ // Instantiate the members of this class template specialization.
+ InstantiatingTemplate Inst(*this, TemplateLoc, Specialization);
+ InstantiateClassTemplateSpecializationMembers(TemplateLoc, Specialization);
+ }
- // Instantiate the members of this class template specialization.
- InstantiatingTemplate Inst(*this, TemplateLoc, Specialization);
- InstantiateClassTemplateSpecializationMembers(TemplateLoc, Specialization);
-
return DeclPtrTy::make(Specialization);
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=71869&r1=71868&r2=71869&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri May 15 12:59:04 2009
@@ -587,6 +587,8 @@
// FIXME: add to the instantiation stack.
+ ActOnStartOfFunctionDef(0, DeclPtrTy::make(Function));
+
// Introduce a new scope where local variable instantiations will be
// recorded.
LocalInstantiationScope Scope(*this);
@@ -605,10 +607,9 @@
// Instantiate the function body.
OwningStmtResult Body
= InstantiateStmt(Pattern, getTemplateInstantiationArgs(Function));
- if (Body.isInvalid())
- Function->setInvalidDecl(true);
- else
- Function->setBody(Body.takeAs<Stmt>());
+
+ ActOnFinishFunctionBody(DeclPtrTy::make(Function), move(Body),
+ /*IsInstantiation=*/true);
CurContext = PreviousContext;
}
Modified: cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp?rev=71869&r1=71868&r2=71869&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp Fri May 15 12:59:04 2009
@@ -1,5 +1,4 @@
// RUN: clang-cc -fsyntax-only -verify %s
-
template<typename T, typename U>
struct X0 {
void f(T x, U y) {
@@ -50,3 +49,12 @@
template struct X4<void>; // expected-note{{in instantiation of template class 'X4<void>' requested here}}
template struct X4<int>; // expected-note{{in instantiation of template class 'X4<int>' requested here}}
+
+struct Incomplete; // expected-note{{forward declaration}}
+
+template<typename T> struct X5 {
+ T f() { } // expected-error{{incomplete result type}}
+};
+void test_X5(X5<Incomplete> x5); // okay!
+
+template struct X5<Incomplete>; // expected-note{{instantiation}}
More information about the cfe-commits
mailing list