[cfe-dev] query AST for C++ method qualifiers

John McCall rjmccall at apple.com
Sun Sep 12 13:23:15 PDT 2010


On Sep 12, 2010, at 8:21 AM, Jan Bierbaum wrote:

> Hi!
> 
> 
> How can I correctly determine the qualifiers used in the declaration of
> a 'CXXMethodDecl'?
> 
> I found
> 'CXXMethodDecl::isStatic()'
> 'CXXMethodDecl::isVirtual()' and
> 'FunctionDecl::isVirtualAsWritten()'
> to work just fine.
> 
> For 'const' and 'volatile' I use 'CXXMethodDecl::getThisType()'
> and then check if the type 'isLocalConstQualified()' or
> 'isLocalVolatileQualified()'. Confusingly I *always* get 'false' from
> these two method calls, but according to getThisType's source code
> comment it's exactly the method I want to use.
> 
> Attached are a small test file, the ASTConsumer code I use for testing
> and the output I get. Any idea what might be wrong here?

The 'this' type is a pointer type;  you would want the qualifiers on its pointee type.  But what you actually want are the qualifiers on the function type itself.

Also, you should generally not be using 'isLocalX', because it doesn't look through type sugar (like a typedef), which it is possible to declare (but not define) a method with.  

John.



More information about the cfe-dev mailing list