Skip to content

Conversation

@Red-RobinHood
Copy link

No description provided.

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-clang

Author: None (Red-RobinHood)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/167157.diff

3 Files Affected:

  • (modified) clang/include/clang/Parse/Parser.h (+2)
  • (modified) clang/lib/Parse/ParseDeclCXX.cpp (+20-1)
  • (modified) clang/lib/Sema/SemaType.cpp (+11)
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index dad8efd0f017f..b7b1b629f2d1e 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3787,6 +3787,8 @@ class Parser : public CodeCompletionHandler {
   /// true except when we are parsing an expression within a C++
   /// template argument list, where the '>' closes the template
   /// argument list.
+  SmallVector<TemplateParameterList *, 4> *TemplateParamsFromAlias = nullptr;
+
   bool GreaterThanIsOperator;
 
   // C++ type trait keywords that can be reverted to identifiers and still be
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index b96968d4592f5..8f30bc3c19409 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -889,6 +889,13 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator(
         << FixItHint::CreateRemoval(SourceRange(D.EllipsisLoc));
 
   Decl *DeclFromDeclSpec = nullptr;
+
+  TemplateParameterLists *SavedTemplateParamsFromAlias =
+      TemplateParamsFromAlias;
+  TemplateParamsFromAlias = TemplateInfo.TemplateParams;
+  TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams;
+  TemplateParamsFromAlias = SavedTemplateParamsFromAlias;
+
   TypeResult TypeAlias =
       ParseTypeName(nullptr,
                     TemplateInfo.Kind != ParsedTemplateKind::NonTemplate ? DeclaratorContext::AliasTemplate
@@ -904,7 +911,7 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator(
                                       : "alias declaration"))
     SkipUntil(tok::semi);
 
-  TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams;
+  TemplateParams = TemplateInfo.TemplateParams;
   MultiTemplateParamsArg TemplateParamsArg(
       TemplateParams ? TemplateParams->data() : nullptr,
       TemplateParams ? TemplateParams->size() : 0);
@@ -1543,6 +1550,18 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
                                  DeclSpecContext DSC,
                                  ParsedAttributes &Attributes) {
   DeclSpec::TST TagType;
+
+  if (TemplateParamsFromAlias) {
+    for (TemplateParameterList *TPL : *TemplateParamsFromAlias) {
+      for (NamedDecl *ND : *TPL) {
+        ND->setInvalidDecl(true);
+        if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(ND)) {
+          TTPD->setTypeForDecl(Actions.Context.IntTy.getTypePtr());
+        }
+      }
+    }
+  }
+
   if (TagTokKind == tok::kw_struct)
     TagType = DeclSpec::TST_struct;
   else if (TagTokKind == tok::kw___interface)
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index eb8b1352d1be1..09c10b1d0cb5c 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3417,6 +3417,17 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
     }
   }
 
+  if (auto *CRD = dyn_cast_or_null<CXXRecordDecl>(OwnedTagDecl)) {
+    if (auto *CTD = CRD->getDescribedClassTemplate()) {
+      for (const NamedDecl *ND : CTD->getTemplateParameters()->asArray()) {
+        if (ND->isInvalidDecl()) {
+          D.setInvalidType(true);
+          return T;
+        }
+      }
+    }
+  }
+
   if (SemaRef.getLangOpts().CPlusPlus &&
       OwnedTagDecl && OwnedTagDecl->isCompleteDefinition()) {
     // Check the contexts where C++ forbids the declaration of a new class

@Red-RobinHood Red-RobinHood deleted the fix-issue-number-91564 branch November 8, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants