Skip to content

Wrong source range for template and templated decl #22846

@Abramo-Bagnara

Description

@Abramo-Bagnara
Bugzilla Link 22472
Version trunk
OS Linux
CC @DougGregor

Extended Description

For the following source:

template <int> struct C { template <typename U> struct D; };
template <int> struct D { template <typename U> void f(); };

template <> template <typename V> struct C<0>::D { };
template <> template <typename V> void D<0>::f();

the AST generated for last two lines is:

|-ClassTemplateDecl 0x8036740 parent 0x8030360 prev 0x80306f0 <line:4:13, col:52> col:48 D
| |-TemplateTypeParmDecl 0x8030290 <col:23, col:32> col:32 typename V
| `-CXXRecordDecl 0x8036670 parent 0x8030360 prev 0x8030660 <col:1, col:52> col:48 struct D definition
|   `-CXXRecordDecl 0x8036810 <col:35, col:48> col:48 implicit struct D
`-FunctionTemplateDecl 0x8036ee0 parent 0x8036950 prev 0x8036cf0 <line:5:13, col:48> col:46 f
  |-TemplateTypeParmDecl 0x80368b0 <col:23, col:32> col:32 typename V
  `-CXXMethodDecl 0x8036df0 parent 0x8036950 prev 0x8036c50 <col:1, col:48> col:46 f 'void (void)'

As it can be observed the templated decls (CXXRecordDecl and CXXMethodDecl) have a range that is larger than the related template decl (ClassTemplateDecl and FunctionTemplateDecl).

This breaks the invariant that asks that inner nodes have a range that is a subset or equal to range of outer nodes.

A sensible approach would be that templated CXXRecordDecl and DeclaratorDecl have the begin of their source range at current InnerLocStart and that the ClassTemplateDecl/FunctionTemplateDecl have the begin of their source range in the location of the outer template keyword.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions