[cfe-dev] how to see in AST fields destruction

Vladimir Voskresensky voskresensky.vladimir at gmail.com
Mon Mar 16 07:31:31 PDT 2015


Hello,

How can I find by AST visitor for which fields destructors are called?

for the following code:
  struct WithDestr {
    int *i;

    WithDestr() : i(nullptr) { }

    virtual ~WithDestr() { delete i; }
  };

  struct Other {
    WithDestr d;
    long *ptr;
    Other() { }
    virtual ~Other() { delete ptr; }
  };

In AST I see only the construction of field d, but do not see anywhere
destruction of d.

|-CXXRecordDecl 0x9130050 <line:13:3, line:18:3> line:13:10 struct Other
definition
| |-CXXRecordDecl 0x9130100 <col:3, col:10> col:10 implicit referenced
struct Other
| |-FieldDecl 0x9130160 <line:14:5, col:15> col:15 d 'struct WithDestr'
| |-FieldDecl 0x91301c0 <line:15:5, col:11> col:11 referenced ptr 'long * '
| |-CXXConstructorDecl 0x9130240 <line:16:5, col:15> col:5 Other 'void
(void) __attribute__((cdecl))'
| | |-CXXCtorInitializer Field 0x9130160 'd' 'struct WithDestr'
| | | `-CXXConstructExpr 0x9176ae8 <col:5> 'struct WithDestr' 'void (void)
__attribute__((cdecl))'
| | `-CompoundStmt 0x9176b30 <col:13, col:15>
| |-CXXDestructorDecl 0x9176850 <line:17:5, col:36> col:13 used ~Other
'void (void) __attribute__((cdecl)) noexcept' virtual
| | `-CompoundStmt 0x9176b98 <col:22, col:36>
| |   `-CXXDeleteExpr 0x9176b80 <col:24, col:31> 'void'
| |     `-ImplicitCastExpr 0x9176b70 <col:31> 'long * ' <LValueToRValue>
| |       `-MemberExpr 0x9176b50 <col:31> 'long * ' lvalue ->ptr 0x91301c0
| |         `-CXXThisExpr 0x9176b40 <col:31> 'struct Other * ' this



Thanks!
Vladimir.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150316/0c4823ab/attachment.html>


More information about the cfe-dev mailing list