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

Richard Smith richard at metafoo.co.uk
Mon Mar 16 11:46:21 PDT 2015


On Mon, Mar 16, 2015 at 7:31 AM, Vladimir Voskresensky <
voskresensky.vladimir at gmail.com> wrote:

> 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.
>

We do not model the implicit member and base destruction actions performed
by a destructor in the AST.


> |-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.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150316/1591b2cc/attachment.html>


More information about the cfe-dev mailing list