[cfe-dev] Different AST translations for the same body, why?
Sebastian Redl
sebastian.redl at getdesigned.at
Wed Apr 11 05:01:15 PDT 2012
On 11.04.2012, at 10:52, Abramo Bagnara wrote:
> I'd like to understand the rationale underlying the different
> translation of body of foo1 and foo2.
>
> It seems that the presence of a totally unrelated operator* change the
> translation.
>
> I don't see any benefits in doing that (as template instantiation will
> do the right thing in both cases).
>
> I'm missing something?
A UnaryOperator node is more lightweight than a CXXOperatorCallExpr node. Therefore, the more heavyweight node is only created if the definition-time name lookup had any results. These results need to be stored for correct two-phase name lookup, and only CXXOperatorCallExpr can do that.
> void foo1() (CompoundStmt 0x585d0c0 <p.cc:8:21, col:38>
> (UnaryExprOrTypeTraitExpr 0x585d0a0 <col:23, col:35> 'unsigned long'
> sizeof
> (ParenExpr 0x585d080 <col:29, col:35> '<dependent type>'
> (UnaryOperator 0x585d060 <col:30, col:31> '<dependent type>'
> prefix '*'
> (CXXThisExpr 0x585d048 <col:31> 'Foo<T> *' this)))))
>
>
> struct Bar;
> Bar &operator*(Bar &, Bar &);
> void foo2() (CompoundStmt 0x585f510 <p.cc:14:21, col:38>
> (UnaryExprOrTypeTraitExpr 0x585f4f0 <col:23, col:35> 'unsigned long'
> sizeof
> (ParenExpr 0x585f4d0 <col:29, col:35> '<dependent type>'
> (CXXOperatorCallExpr 0x585f498 <col:30, col:31> '<dependent type>'
> (UnresolvedLookupExpr 0x585f440 <col:30> '<overloaded function
> type>' lvalue (ADL) = '1' 0x585d310)
> (CXXThisExpr 0x585f428 <col:31> 'Foo<T> *' this)))))
>
Sebastian
More information about the cfe-dev
mailing list