Parse a simple-template-id following a '~' when calling a destructor, e.g.,

  t->~T<A0, A1>()

Fixes PR5213.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84545 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 72e30e3..8be89a8 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -972,13 +972,41 @@
           return ExprError();
         }
 
-        if (!LHS.isInvalid())
-          LHS = Actions.ActOnDestructorReferenceExpr(CurScope, move(LHS),
-                                                     OpLoc, OpKind,
-                                                     Tok.getLocation(),
-                                                     Tok.getIdentifierInfo(),
-                                                     SS,
-                                               NextToken().is(tok::l_paren));
+        if (NextToken().is(tok::less)) {
+          // class-name: 
+          //     ~ simple-template-id
+          TemplateTy Template 
+            = Actions.ActOnDependentTemplateName(SourceLocation(),
+                                                 *Tok.getIdentifierInfo(),   
+                                                 Tok.getLocation(),
+                                                 SS,
+                                                 ObjectType);
+          if (AnnotateTemplateIdToken(Template, TNK_Type_template, &SS, 
+                                      SourceLocation(), true))
+            return ExprError();
+          
+          assert(Tok.is(tok::annot_typename) && 
+                 "AnnotateTemplateIdToken didn't work?");
+          if (!LHS.isInvalid())
+            LHS = Actions.ActOnDestructorReferenceExpr(CurScope, move(LHS),
+                                                       OpLoc, OpKind,
+                                                       Tok.getAnnotationRange(),
+                                                       Tok.getAnnotationValue(),
+                                                       SS,
+                                                 NextToken().is(tok::l_paren));                                                                   
+        } else {
+          // class-name: 
+          //     ~ identifier
+          if (!LHS.isInvalid())
+            LHS = Actions.ActOnDestructorReferenceExpr(CurScope, move(LHS),
+                                                       OpLoc, OpKind,
+                                                       Tok.getLocation(),
+                                                       Tok.getIdentifierInfo(),
+                                                       SS,
+                                                 NextToken().is(tok::l_paren));
+        }
+        
+        // Consume the identifier or template-id token.
         ConsumeToken();
       } else if (getLang().CPlusPlus && Tok.is(tok::kw_operator)) {
         // We have a reference to a member operator, e.g., t.operator int or