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

Douglas Gregor dgregor at apple.com
Sun Sep 12 16:25:35 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.


John's advice is correct w.r.t the result of getThisType() and the use of the cv-qualification checks. However, there's a simpler way for this specific task: CXXMethodDecl::getTypeQualifiers() gives you a bitmask of the const and volatile qualifiers.

	- Doug



More information about the cfe-dev mailing list