[cfe-dev] Doubt about AST

Abramo Bagnara abramo.bagnara at gmail.com
Thu Jun 17 04:43:22 PDT 2010


$ cat y1.cc
template <typename T>
struct S {
  int operator=(int v);
  int f() {
    return *this = 2;
  }
};

$ ~/llvm/Debug/bin/clang -cc1 -ast-dump y1.cc
typedef char *__builtin_va_list;
template <typename T> struct S {
    struct S;
    int operator=(int v);
    int f() (CompoundStmt 0xa839ed0 <y1.cc:4:11, line:6:3>
  (ReturnStmt 0xa839eb8 <line:5:5, col:20>
    (BinaryOperator 0xa839e90 <col:12, col:20> '<dependent type>' '='
      (CXXOperatorCallExpr 0xa839e40 <col:12, col:13> '<dependent type>'
        (UnresolvedLookupExpr 0xa839e08 <col:12> '<dependent type>'
(ADL) = '1' empty)
        (CXXThisExpr 0xa839de8 <col:13> 'S<T> *' this))
      (IntegerLiteral 0xa839e68 <col:20> 'int' 2))))


};

I'd like to understand why *this is converted in CXXOperatorCallExpr of
UnresolvedLookupExpr instead of UnaryOperator deref.

The deref operator for this might be overloaded? How?

I'd like also to understand in which situations clang choose to emit
something like BinaryOperator (then instantiated in operator call) and
when choose to emit an operator call also on primary template (of course
when both choices might be done).



More information about the cfe-dev mailing list