Skip to content

CTAD: crash on erroneous alias templates #85406

@hokein

Description

@hokein

Given the following incorrect code:

template <typename T>
class Foo {};

template <typename T>
template <typename K>
using Bar2 = Foo<K>; // error: Extraneous template parameter list in alias template declaration

Bar2 b = 1;

The alias template declaration is invalid because of the extra template parameter list, clang still builds the decl for error recovery, the AST looks like:

-TypeAliasTemplateDecl 0x55d41b04fc00 <line:33:1, line:35:19> col:1 invalid Bar2
| |-TemplateTypeParmDecl 0x55d41b04f910 <line:33:10, col:19> col:19 typename depth 0 index 0 T
| `-TypeAliasDecl 0x55d41b04fba0 <line:35:1, col:19> col:7 Bar2 'Foo<K>'
|   `-ElaboratedType 0x55d41b04fb30 'Foo<K>' sugar dependent
|     `-TemplateSpecializationType 0x55d41b04fae0 'Foo<K>' dependent Foo
|       `-TemplateArgument type 'K'
|         `-TemplateTypeParmType 0x55d41b04fa30 'K' dependent depth 1 index 0
|           `-TemplateTypeParm 0x55d41b04f9a8 'K'

The TypeAliasTemplateDecl is ill-formed for this case -- the template parameter list of the alias decl is the first written one (which is T), while in the alias decl body, we have nodes that refer to the template parameter K. And the invalid bit of the alias decl is not flagged.

This ill-formed AST node breaks invariant for the downstream AST consumer. The crash inside CTAD is a symptom. We should at least mark the decl invalid for this case.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions