Skip to content

Commit 63ea5a4

Browse files
authored
[clang] Invalidate the alias template decl if it has multiple written template parameter lists. (#85413)
Fixes #85406. - Set the invalid bit for alias template decl where it has multiple written template parameter lists (as the AST node is ill-formed) - don't perform CTAD for invalid alias template decls
1 parent 38f5596 commit 63ea5a4

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13589,6 +13589,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, AccessSpecifier AS,
1358913589
Diag(UsingLoc, diag::err_alias_template_extra_headers)
1359013590
<< SourceRange(TemplateParamLists[1]->getTemplateLoc(),
1359113591
TemplateParamLists[TemplateParamLists.size()-1]->getRAngleLoc());
13592+
Invalid = true;
1359213593
}
1359313594
TemplateParameterList *TemplateParams = TemplateParamLists[0];
1359413595

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,8 @@ bool hasDeclaredDeductionGuides(DeclarationName Name, DeclContext *DC) {
27312731
// Build deduction guides for a type alias template.
27322732
void DeclareImplicitDeductionGuidesForTypeAlias(
27332733
Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate, SourceLocation Loc) {
2734+
if (AliasTemplate->isInvalidDecl())
2735+
return;
27342736
auto &Context = SemaRef.Context;
27352737
// FIXME: if there is an explicit deduction guide after the first use of the
27362738
// type alias usage, we will not cover this explicit deduction guide. fix this

clang/test/AST/ast-dump-invalid.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ double Str::foo1(double, invalid_type)
6060
// CHECK-NEXT: `-ReturnStmt {{.*}} <col:3, col:10>
6161
// CHECK-NEXT: `-ImplicitCastExpr {{.*}} <col:10> 'double' <IntegralToFloating>
6262
// CHECK-NEXT: `-IntegerLiteral {{.*}} <col:10> 'int' 45
63+
64+
namespace TestAliasTemplateDecl {
65+
template<typename T> class A;
66+
67+
template<typename T>
68+
template<typename U> using InvalidAlias = A<U>;
69+
// CHECK: TypeAliasTemplateDecl {{.*}} invalid InvalidAlias
70+
// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
71+
}

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,15 @@ using Bar = Foo<U>; // expected-note {{could not match 'Foo<type-parameter-0-0>'
247247

248248
Bar s = {1}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}}
249249
} // namespace test18
250+
251+
// GH85406, verify no crash on invalid alias templates.
252+
namespace test19 {
253+
template <typename T>
254+
class Foo {};
255+
256+
template <typename T>
257+
template <typename K>
258+
using Bar2 = Foo<K>; // expected-error {{extraneous template parameter list in alias template declaration}}
259+
260+
Bar2 b = 1; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}}
261+
} // namespace test19

0 commit comments

Comments
 (0)