SourceLocations for faux subexpressions of CXXForRangeStmt

I recently did an AST dump of CXXForRangeStmt, which led to the discover that the "faux" expressions representing the semantics of this statement have actual SourceLocations:

  (CXXForRangeStmt 0x7fb8db83dad8 <line:4:3, col:34>
    (DeclStmt 0x7fb8db83d5a8 <col:17>
      0x7fb8db83d3a0 "auto int (&&__range)[2] =
        (DeclRefExpr 0x7fb8db83d260 <col:17> 'int [2]' lvalue Var 0x7fb8db83d030 'array' 'int [2]')")
    (DeclStmt 0x7fb8db83d8e8 <col:15>
      0x7fb8db83d600 "auto int *__begin =
        (ImplicitCastExpr 0x7fb8db83d7c0 <col:15> 'int *' <ArrayToPointerDecay>
      ...

I'm trying to understand why we would do this, as this could possibly pose problems with clients that want to reason about how the source was actually written. These expressions don't actually appear in the source. Should they even have valid SourceLocations?

Cheers,
Ted

IMHO locations for generated nodes should point to generating nodes
(just like template instantiations).

I recently did an AST dump of CXXForRangeStmt, which led to the discover that the "faux" expressions representing the semantics of this statement have actual SourceLocations:

(CXXForRangeStmt 0x7fb8db83dad8 <line:4:3, col:34>
   (DeclStmt 0x7fb8db83d5a8 <col:17>
     0x7fb8db83d3a0 "auto int (&&__range)[2] =
       (DeclRefExpr 0x7fb8db83d260 <col:17> 'int [2]' lvalue Var 0x7fb8db83d030 'array' 'int [2]')")
   (DeclStmt 0x7fb8db83d8e8 <col:15>
     0x7fb8db83d600 "auto int *__begin =
       (ImplicitCastExpr 0x7fb8db83d7c0 <col:15> 'int *' <ArrayToPointerDecay>
     ...

I'm trying to understand why we would do this, as this could possibly pose problems with clients that want to reason about how the source was actually written. These expressions don't actually appear in the source. Should they even have valid SourceLocations?

IMHO locations for generated nodes should point to generating nodes
(just like template instantiations).

+1, I think given any Stmt* we should be able to know where in source code it was written/generated, otherwise we add unnecessary complexity to clients (imagine just traversing the ast inside a specific source range)

FWIW: +1, because it would make implementing source-to-source transformations easier.

-- Erik