[cfe-dev] Issue with CXXCtorInitializer and CXXConstructExpr

victor pedretti_86 at hotmail.com
Fri Jun 27 02:46:14 PDT 2014


Hi,

When I'm iterating the initializers of a constructor declaration (CXXConstructDecl), I access to the elements of type:

CXXConstructorDecl::init_const_iterator

which is actually:

typedef CXXCtorInitializer* const* clang::CXXConstructorDecl::init_const_iterator

Then, to obtain the CXXConstructExpr* from the CXXCtorInitializer*, I perform a casting with:

CXXConstructExpr *ce = (CXXConstructExpr*)(initializer)->getInit();

This worked correctly up to now, but I found that sometimes, the casting is not doing what it was expected and the result is not right. I have detected two problems:

1. If I have the next initializer, where the argument is not a variable or constant directly:
KeyValueContainer(node.elementsByTagName("KEYVALUEPAIRS").item(0).toElement())
When asking:
CXXConstructExpr *ce = (CXXConstructExpr*)(initializer)->getInit();
if (ce->getNumArgs() == 0)

the conditional statement is evaluated to true, when it should be evaluated to false as the constructor has one argument. 

2. Having this:

template <class Key, class T>
class MyMap : protected QMap<Key, T>
...



	
	
	
	MyMap(): QMap<Key, T>() ...

If I print the range of the CXXConstructExpr created from the initializer "QMap<Key, T>()", the result is only the parentheses: (), nothing more. 



The question is:
- Is there another way to obtain the CXXConstructExpr* from the CXXCtorInitializer*?
- Otherwise, how could I check if the object pointed by  CXXConstructExpr* is formed correct? I cannot find nothing similar to "isValid" or something like that.

Thanks.
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140627/e41879e1/attachment.html>


More information about the cfe-dev mailing list