Skip to content

Commit 2bea7af

Browse files
committed
Attempt to fix issue number 91564
1 parent ace77c2 commit 2bea7af

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,8 @@ class Parser : public CodeCompletionHandler {
37873787
/// true except when we are parsing an expression within a C++
37883788
/// template argument list, where the '>' closes the template
37893789
/// argument list.
3790+
SmallVector<TemplateParameterList *, 4> *TemplateParamsFromAlias = nullptr;
3791+
37903792
bool GreaterThanIsOperator;
37913793

37923794
// C++ type trait keywords that can be reverted to identifiers and still be

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,13 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator(
889889
<< FixItHint::CreateRemoval(SourceRange(D.EllipsisLoc));
890890

891891
Decl *DeclFromDeclSpec = nullptr;
892+
893+
TemplateParameterLists *SavedTemplateParamsFromAlias =
894+
TemplateParamsFromAlias;
895+
TemplateParamsFromAlias = TemplateInfo.TemplateParams;
896+
TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams;
897+
TemplateParamsFromAlias = SavedTemplateParamsFromAlias;
898+
892899
TypeResult TypeAlias =
893900
ParseTypeName(nullptr,
894901
TemplateInfo.Kind != ParsedTemplateKind::NonTemplate ? DeclaratorContext::AliasTemplate
@@ -904,7 +911,7 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator(
904911
: "alias declaration"))
905912
SkipUntil(tok::semi);
906913

907-
TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams;
914+
TemplateParams = TemplateInfo.TemplateParams;
908915
MultiTemplateParamsArg TemplateParamsArg(
909916
TemplateParams ? TemplateParams->data() : nullptr,
910917
TemplateParams ? TemplateParams->size() : 0);
@@ -1543,6 +1550,18 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
15431550
DeclSpecContext DSC,
15441551
ParsedAttributes &Attributes) {
15451552
DeclSpec::TST TagType;
1553+
1554+
if (TemplateParamsFromAlias) {
1555+
for (TemplateParameterList *TPL : *TemplateParamsFromAlias) {
1556+
for (NamedDecl *ND : *TPL) {
1557+
ND->setInvalidDecl(true);
1558+
if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(ND)) {
1559+
TTPD->setTypeForDecl(Actions.Context.IntTy.getTypePtr());
1560+
}
1561+
}
1562+
}
1563+
}
1564+
15461565
if (TagTokKind == tok::kw_struct)
15471566
TagType = DeclSpec::TST_struct;
15481567
else if (TagTokKind == tok::kw___interface)

clang/lib/Sema/SemaType.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,17 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
34173417
}
34183418
}
34193419

3420+
if (auto *CRD = dyn_cast_or_null<CXXRecordDecl>(OwnedTagDecl)) {
3421+
if (auto *CTD = CRD->getDescribedClassTemplate()) {
3422+
for (const NamedDecl *ND : CTD->getTemplateParameters()->asArray()) {
3423+
if (ND->isInvalidDecl()) {
3424+
D.setInvalidType(true);
3425+
return T;
3426+
}
3427+
}
3428+
}
3429+
}
3430+
34203431
if (SemaRef.getLangOpts().CPlusPlus &&
34213432
OwnedTagDecl && OwnedTagDecl->isCompleteDefinition()) {
34223433
// Check the contexts where C++ forbids the declaration of a new class

0 commit comments

Comments
 (0)