Problem with source ranges for template classes

Abramo Bagnara abramo.bagnara at bugseng.com
Wed Feb 4 01:02:41 PST 2015


Using this source:

template <int> struct C { template <typename U> struct D; };
template <> template <typename V> struct C<0>::D { };

we get the following AST for the second line

`-ClassTemplateDecl 0x8596370 parent 0x8595cf0 prev 0x8596080
<line:2:13, col:52> col:48 D
  |-TemplateTypeParmDecl 0x8595c20 <col:23, col:32> col:32 typename V
  `-CXXRecordDecl 0x85962a0 parent 0x8595cf0 prev 0x8595ff0 <col:1,
col:52> col:48 struct D definition
    `-CXXRecordDecl 0x8596440 <col:35, col:48> col:48 implicit struct D

Reading the dump we can note that the range of outer node
ClassTemplateDecl (col 13-52) is smaller than the one of inner node
CXXRecordDecl (col 1-52).

This violates an (IMHO) important invariant where it is expected that
inner nodes have a range that is a subset or equal to range of outer nodes.

I'd think that the CXXRecordDecl range should begin from col 35 and the
ClassTemplateDecl range should begin from col 1.

Does this sound reasonable?

-- 
Abramo Bagnara

BUGSENG srl - http://bugseng.com
mailto:abramo.bagnara at bugseng.com



More information about the cfe-commits mailing list