================
@@ -1269,10 +1269,17 @@ class AnnotatingParser {
     if (CurrentToken && CurrentToken->is(tok::less)) {
       CurrentToken->setType(TT_TemplateOpener);
       next();
-      if (!parseAngle())
+      TemplateDeclarationDepth++;
+      if (!parseAngle()) {
+        TemplateDeclarationDepth--;
         return false;
-      if (CurrentToken)
+      }
+      TemplateDeclarationDepth--;
+      if (CurrentToken &&
+          (TemplateDeclarationDepth == 0 ||
+           !CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) {
----------------
owenca wrote:

Maybe something like the following?
```
-  bool parseTemplateDeclaration() {
+  bool parseTemplateDeclaration(bool InTemplateParameter) {
     if (CurrentToken && CurrentToken->is(tok::less)) {
       CurrentToken->setType(TT_TemplateOpener);
+      InTemplateDeclaration = true;
       next();
       if (!parseAngle())
         return false;
-      if (CurrentToken)
-        CurrentToken->Previous->ClosesTemplateDeclaration = true;
+      if (!InTemplateParameter) {
+        InTemplateDeclaration = false;
+        if (CurrentToken)
+          CurrentToken->Previous->ClosesTemplateDeclaration = true;
+      }
       return true;
     }
```
And call it in `consumeToken()` like this:
```
     case tok::kw_template:
-      parseTemplateDeclaration();
+      parseTemplateDeclaration(InTemplateDeclaration);
       break;
```

https://github.com/llvm/llvm-project/pull/95025
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to