<div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div><br></div><div>I am using <i>CXXCtorInitializer</i>'s method <i>getInit()</i> to retrieve its <i>Init</i> Stmt*.<br>The <i>CXXCtorInitializer::Init</i> field is described as followed:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><i>"The argument used to initialize the base or member, which may end up constructing an object (when multiple arguments are involved)."</i></blockquote><div><div><br></div><div>In my usecase I actually want to retrieve the underlying source text, that is represented by <i>Init.</i></div><div><i><br></i></div><div>This works fine for simple Initializers using declRefExpr or integerLiterals.<br></div><div>Retrieving the source's text for the <i>Init</i> expr returns <i>i </i>and <i>10</i> for the following CXXCtorInitializer:</div><div><i><br></i></div><div><i>SomeConstructor(int i):m_foo(i), m_bar(10){}</i></div><div><i><br></i></div><div>I haven't figured out what exactly is the problem, but as far as I can tell the <i>Init</i> pointer appears faulty in some cases when there is a <i>CXXConstructExpr involved.</i></div><div><i><br></i></div><div>Given:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><i>struct T {};<br></i><i>struct Foo{<br></i><i>    Foo(T t): t0(new T()),  t1({}),   t2(t){}</i><i><br></i><i>    T * t0;<br></i><i>    T t1;<br></i><i>    T t2;<br></i><i>};</i></blockquote><div><br></div><div>Retrieving the <i>Init</i> and it's underlying source text returns:</div><div>for t0: "<i>new T()</i>"    <----- as expected :)</div><div>for t1: "<i>t1({})</i>"        <----- expected: "<i>{}</i>" </div><div>for t2: "<i>t2(t)</i>"          <---- expected: "<i>t</i>"</div><div><br></div><div>Since the Docu states, the <i>Init</i> gives the<i> "</i><i>argument used to initialize the [...] member"</i> I think this might be a bug? Maybe I don't retrieve the source code correctly, but in any other case it appears to work just fine.</div><div><div>I use the Lexer to get to the<i> Init</i>'s source like this, where expr is <i>cxxCtorInitializer->getInit()</i>:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><i>Lexer::getSourceText(CharSourceRange::getCharRange(expr->getSourceRange()), ctxt.getSourceManager(), ctxt.getLangOpts());</i></blockquote><div><i><br></i></div><div>So is this expected behavior? If so why? And how can I get to the actual 'Initializer' in those cases?</div><div><br></div><div>Any help appreciated!</div><br class="gmail-Apple-interchange-newline"></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Mit freundlichen Grüßen,</div><div>Julian Müller<div><br></div></div></div></div></div></div></div></div></div></div>