<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Gregory,<div class=""><br class=""></div><div class="">These Sema methods might also be of interest:</div><div class="">Sema::DeclareImplicitDefaultConstructor</div><div class="">Sema::DeclareImplicitCopyAssignment</div><div class="">Sema::DeclareImplicitCopyConstructor</div><div class="">(+ Move versions)</div><div class=""><br class=""></div><div class="">Hope this helps!</div><div class=""><br class=""></div><div class="">Jan<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 23, 2019, at 6:30 AM, Anastasia Stulova via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class="">Hi Gregory,<div style="" class=""><div dir="ltr" class=""><div id="x_divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class=""><div dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class=""><br class=""></div><div dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class="">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; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class=""><br class=""></div><div dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;" class=""><div class="">As far as I am aware Clang generates all declarations of special members lazily (ctors are added in<b class=""><span class="Apple-converted-space"> </span></b><b class="">Sema::LookupConstructors()<span class="Apple-converted-space"> </span></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 class="">DeferredDeclsToEmit</b><span class="Apple-converted-space"> </span>of<span class="Apple-converted-space"> </span><b class="">CodeGenModule::GetOrCreateLLVMFunction()</b><span class="Apple-converted-space"> </span>when it encounters their uses. At the end of the module generation <span class=""><b class="">CodeGenModule::EmitDeferred()</b><span class="Apple-converted-space"> </span>will be called to emit definitions of implicit special members in IR.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">The AST dump of your example will look like this:</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class=""><div class="">|-CXXRecordDecl 0x20c7c48 <test.cpp:1:1, col:10> col:7 referenced class P definition<br class="">| |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init<br class="">| | |-DefaultConstructor exists trivial constexpr defaulted_is_constexpr<br class="">| | |-CopyConstructor simple trivial has_const_param implicit_has_const_param<br class="">| | |-MoveConstructor exists simple trivial<br class="">| | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param<br class="">| | |-MoveAssignment exists simple trivial needs_implicit<br class="">| | `-Destructor simple irrelevant trivial needs_implicit<br class="">| |-CXXRecordDecl 0x20c7d58 <col:1, col:7> col:7 implicit class P<br class="">| |-CXXConstructorDecl 0x20c7fe0 <col:7> col:7 implicit used constexpr P 'void () noexcept' inline default trivial<br class="">| | `-CompoundStmt 0x20c8448 <col:7><br class="">| |-CXXConstructorDecl 0x20c8108 <col:7> col:7 implicit constexpr P 'void (const P &)' inline default trivial noexcept-unevaluated 0x20c8108<br class="">| | `-ParmVarDecl 0x20c8218 <col:7> col:7 'const P &'<br class="">| `-CXXConstructorDecl 0x20c82a8 <col:7> col:7 implicit constexpr P 'void (P &&)' inline default trivial noexcept-unevaluated 0x20c82a8<br class="">|   `-ParmVarDecl 0x20c83b8 <col:7> col:7 'P &&'<br class="">`-FunctionDecl 0x20c7e50 <line:2:1, line:5:1> line:2:5 main 'int ()'<br class="">  `-CompoundStmt 0x20c84c8 <col:12, line:5:1><br class="">    |-DeclStmt 0x20c8480 <line:3:4, col:7><br class="">    | `-VarDecl 0x20c7f68 <col:4, col:6> col:6 x 'P' callinit<br class="">    |   `-CXXConstructExpr 0x20c8458 <col:6> 'P' 'void () noexcept'<br class="">    `-ReturnStmt 0x20c84b8 <line:4:4, col:11><br class="">      `-IntegerLiteral 0x20c8498 <col:11> 'int'<span class="Apple-converted-space"> </span><br class=""></div><br class=""></span></div><div class=""><span class="">As you can see that only declarations of the implicit special members appear in AST.<br class=""></span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Cheers,</span></div><div class=""><span class="">Anastasia<br class=""></span></div><br class=""><div style="" class=""><hr tabindex="-1" style="display: inline-block; width: 1142.671875px;" class=""><div id="x_divRplyFwdMsg" dir="ltr" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>cfe-dev <<a href="mailto:cfe-dev-bounces@lists.llvm.org" class="">cfe-dev-bounces@lists.llvm.org</a>> on behalf of Gregory Malecha via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>22 January 2019 11:48<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>[cfe-dev] What code generates default constructors?</font><div class=""> </div></div><div class=""><div dir="ltr" class="">Hello --<div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Very concretely, if I write the following code:</div><div class=""><br class=""></div><div class="">class P {};</div><div class="">int main() {</div><div class="">   P x;</div><div class="">   return 0;</div><div class="">}</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Thank you.</div><div class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div dir="ltr" class="x_x_gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">gregory malecha</div><div class=""><a href="https://gmalecha.github.io/" target="_blank" class="">gmalecha.github.io</a></div></div></div></div></div></div></div></div></div></div></div></div></div></div><span style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;" class="">_______________________________________________</span><br style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;" class="">cfe-dev mailing list</span><br style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;" class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a></span><br style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></span></div></blockquote></div><br class=""></div></body></html>