Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down