]> granicus.if.org Git - clang/commitdiff
Instantiate goto and label statements. (Very useful, I know)
authorAnders Carlsson <andersca@mac.com>
Fri, 15 May 2009 00:15:26 +0000 (00:15 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 15 May 2009 00:15:26 +0000 (00:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71822 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateExpr.cpp
test/SemaTemplate/instantiate-function-1.cpp

index 2dca993f741ea766963c07880611c1faa4450c87..e747236204b4d9e8a0ec3fe188ed3fbe67b24f6c 100644 (file)
@@ -445,6 +445,8 @@ namespace {
     OwningStmtResult VisitNullStmt(NullStmt *S);
     OwningStmtResult VisitCompoundStmt(CompoundStmt *S);
     OwningStmtResult VisitExpr(Expr *E);
+    OwningStmtResult VisitLabelStmt(LabelStmt *S);
+    OwningStmtResult VisitGotoStmt(GotoStmt *S);
 
     // Base case. I'm supposed to ignore this.
     OwningStmtResult VisitStmt(Stmt *S) { 
@@ -481,6 +483,22 @@ Sema::OwningStmtResult TemplateStmtInstantiator::VisitNullStmt(NullStmt *S) {
   return SemaRef.Owned(new (SemaRef.Context) NullStmt(S->getSemiLoc()));
 }
 
+Sema::OwningStmtResult TemplateStmtInstantiator::VisitLabelStmt(LabelStmt *S) {
+  OwningStmtResult SubStmt = Visit(S->getSubStmt());
+
+  if (SubStmt.isInvalid())
+    return SemaRef.StmtError();
+  
+  // FIXME: Pass the real colon loc in.
+  return SemaRef.ActOnLabelStmt(S->getIdentLoc(), S->getID(), SourceLocation(), 
+                                move(SubStmt));
+}
+
+Sema::OwningStmtResult TemplateStmtInstantiator::VisitGotoStmt(GotoStmt *S) {
+  return SemaRef.ActOnGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 
+                               S->getLabel()->getID());
+}
+
 Sema::OwningStmtResult 
 TemplateStmtInstantiator::VisitCompoundStmt(CompoundStmt *S) {
   // FIXME: We need an *easy* RAII way to delete these statements if
index 6b755c8ea954912623a6350f68b73910f73b6981..5ca34019480539bc0a3e129a8b57116de68be255 100644 (file)
@@ -26,3 +26,14 @@ struct X2 {
 
 template struct X2<int>;
 template struct X2<int&>; // expected-note{{instantiation of}}
+
+template<typename T>
+struct X3 {
+  void f(T) {
+    Label:
+    T x;
+    goto Label;
+  }
+};
+
+template struct X3<int>;