[cfe-dev] Bug? CXXCtorInitializer::getInit()

Julian Mueller via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 21 02:46:18 PST 2018


Hello,

I am using *CXXCtorInitializer*'s method *getInit()* to retrieve its *Init*
 Stmt*.
The *CXXCtorInitializer::Init* field is described as followed:

*"The argument used to initialize the base or member, which may end up
> constructing an object (when multiple arguments are involved)."*


In my usecase I actually want to retrieve the underlying source text, that
is represented by *Init.*

This works fine for simple Initializers using declRefExpr or
integerLiterals.
Retrieving the source's text for the *Init* expr returns *i *and *10* for
the following CXXCtorInitializer:

*SomeConstructor(int i):m_foo(i), m_bar(10){}*

I haven't figured out what exactly is the problem, but as far as I can tell
the *Init* pointer appears faulty in some cases when there is a
*CXXConstructExpr
involved.*

Given:


> *struct T {};*
> *struct Foo{**    Foo(T t): t0(new T()),  t1({}),   t2(t){}*
>
> *    T * t0;*
> *    T t1;*
> *    T t2;**};*


Retrieving the *Init* and it's underlying source text returns:
for t0: "*new T()*"    <----- as expected :)
for t1: "*t1({})*"        <----- expected: "*{}*"
for t2: "*t2(t)*"          <---- expected: "*t*"

Since the Docu states, the *Init* gives the* "**argument used to initialize
the [...] member"* 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.
I use the Lexer to get to the* Init*'s source like this, where expr is
*cxxCtorInitializer->getInit()*:

*Lexer::getSourceText(CharSourceRange::getCharRange(expr->getSourceRange()),
> ctxt.getSourceManager(), ctxt.getLangOpts());*


So is this expected behavior? If so why? And how can I get to the actual
'Initializer' in those cases?

Any help appreciated!

-- 
Mit freundlichen Grüßen,
Julian Müller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181221/4eccb006/attachment-0001.html>


More information about the cfe-dev mailing list