<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" dir="ltr">
Hi Gregory,
<div style="color: rgb(0, 0, 0);">
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<br>
</div>
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
I am not familiar with libtooling but if you use Clang driver I don't think that the implicit constructors are actually generated in the AST.</div>
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<br>
</div>
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div>As far as I am aware Clang generates all declarations of special members lazily (ctors are added in<b>
</b><b>Sema::LookupConstructors() </b>for example). It seems however the definitions are generated only for the ones that are actually used during the CodeGen phase.  Clang memorizes special members by putting them in
<b>DeferredDeclsToEmit</b> of <b>CodeGenModule::GetOrCreateLLVMFunction()</b> when it encounters their uses. At the end of the module generation <span><b>CodeGenModule::EmitDeferred()</b> will be called to emit definitions of implicit special members in IR.</span></div>
<div><span><br>
</span></div>
<div><span>The AST dump of your example will look like this:</span></div>
<div><span><br>
</span></div>
<div><span>
<div>|-CXXRecordDecl 0x20c7c48 <test.cpp:1:1, col:10> col:7 referenced class P definition<br>
| |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init<br>
| | |-DefaultConstructor exists trivial constexpr defaulted_is_constexpr<br>
| | |-CopyConstructor simple trivial has_const_param implicit_has_const_param<br>
| | |-MoveConstructor exists simple trivial<br>
| | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param<br>
| | |-MoveAssignment exists simple trivial needs_implicit<br>
| | `-Destructor simple irrelevant trivial needs_implicit<br>
| |-CXXRecordDecl 0x20c7d58 <col:1, col:7> col:7 implicit class P<br>
| |-CXXConstructorDecl 0x20c7fe0 <col:7> col:7 implicit used constexpr P 'void () noexcept' inline default trivial<br>
| | `-CompoundStmt 0x20c8448 <col:7><br>
| |-CXXConstructorDecl 0x20c8108 <col:7> col:7 implicit constexpr P 'void (const P &)' inline default trivial noexcept-unevaluated 0x20c8108<br>
| | `-ParmVarDecl 0x20c8218 <col:7> col:7 'const P &'<br>
| `-CXXConstructorDecl 0x20c82a8 <col:7> col:7 implicit constexpr P 'void (P &&)' inline default trivial noexcept-unevaluated 0x20c82a8<br>
|   `-ParmVarDecl 0x20c83b8 <col:7> col:7 'P &&'<br>
`-FunctionDecl 0x20c7e50 <line:2:1, line:5:1> line:2:5 main 'int ()'<br>
  `-CompoundStmt 0x20c84c8 <col:12, line:5:1><br>
    |-DeclStmt 0x20c8480 <line:3:4, col:7><br>
    | `-VarDecl 0x20c7f68 <col:4, col:6> col:6 x 'P' callinit<br>
    |   `-CXXConstructExpr 0x20c8458 <col:6> 'P' 'void () noexcept'<br>
    `-ReturnStmt 0x20c84b8 <line:4:4, col:11><br>
      `-IntegerLiteral 0x20c8498 <col:11> 'int' <br>
</div>
<br>
</span></div>
<div><span>As you can see that only declarations of the implicit special members appear in AST.<br>
</span></div>
<div><span><br>
</span></div>
<div><span>Cheers,</span></div>
<div><span>Anastasia<br>
</span></div>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> cfe-dev <cfe-dev-bounces@lists.llvm.org> on behalf of Gregory Malecha via cfe-dev <cfe-dev@lists.llvm.org><br>
<b>Sent:</b> 22 January 2019 11:48<br>
<b>To:</b> cfe-dev@lists.llvm.org<br>
<b>Subject:</b> [cfe-dev] What code generates default constructors?</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hello --
<div><br>
</div>
<div>I'm trying to understand how ASTs for constructors are generated when they are referenced. In particular, I'm working on a libtooling tool that will dump the AST to another format on a per-file basis so I need to know the code for any constructors even
 if they are not called in the file.</div>
<div><br>
</div>
<div>Very concretely, if I write the following code:</div>
<div><br>
</div>
<div>class P {};</div>
<div>int main() {</div>
<div>   P x;</div>
<div>   return 0;</div>
<div>}</div>
<div><br>
</div>
<div>the result of -ast-dump will contain the implementation of the default constructor (not very interesting in this case). What code generates this?</div>
<div><br>
</div>
<div>Thank you.</div>
<div>
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_x_gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>gregory malecha</div>
<div><a href="https://gmalecha.github.io" target="_blank">gmalecha.github.io</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>