]> granicus.if.org Git - clang/commitdiff
Fix a double free when parsing malformed code. Fixes rdar://9173693.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 3 May 2011 18:45:38 +0000 (18:45 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 3 May 2011 18:45:38 +0000 (18:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130775 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/SemaTemplate/rdar9173693.cpp [new file with mode: 0644]

index 8bf6f63d3ecd2e1638439719b0da38a3cba055bf..eb491ef2bb0375cd199d10d3789209f3bedc3886 100644 (file)
@@ -280,8 +280,11 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
                                       : TemplateId->TemplateNameLoc;
         SS.SetInvalid(SourceRange(StartLoc, CCLoc));
       }
-      
-      TemplateId->Destroy();
+
+      // If we are caching tokens we will process the TemplateId again,
+      // otherwise destroy it.
+      if (!PP.isBacktrackEnabled())
+        TemplateId->Destroy();
       continue;
     }
 
diff --git a/test/SemaTemplate/rdar9173693.cpp b/test/SemaTemplate/rdar9173693.cpp
new file mode 100644 (file)
index 0000000..86b4954
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/9173693>
+template< bool C > struct assert { };
+template< bool > struct assert_arg_pred_impl { }; // expected-note 3 {{declared here}}
+template< typename Pred > assert<false> assert_not_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type ); // expected-error 5 {{}}