Return Type Location

How do I get a SourceLocation for a FunctionDecl return type? FunctionDecl::getReturnType() returns QualType, and I don’t think that I can get source locations from there.

What about getTypeSpecStartLoc? FunctionDecl is derived from a number of classes, the method is likely to be in one of them.

That seems to work for the simple case but not for the case with namespace qualifiers. How would that be modified to handle a qualified name?

So in case of say

namespace MyNS
{
class MyClass {};
}

MyNs::MyClass foo();

You’d like to get the location pointing to MyClass?

TypeLoc TL = FunctionDecl->getTypeSourceInfo()->getTypeLoc();
FunctionTypeLoc FTL = TL.getAs();
ElaboratedTypeLoc ETL = FTL.getReturnLoc().getAs();
ETL.getNamedTypeLoc().getBeginLoc();

Nikola

Hi Daniel,

That's a good feature request. The facility was previously tucked away deep in Sema but we usually make an effort to expose the most useful source ranges in the primary interface.

So I've introduced FunctionDecl::getReturnTypeSourceRange() in r212154 and used it to enhance various diagnostics. Hope it helps with your use case too.

Alp.