[cfe-dev] Difference between getResultType adn getCallResultType
Jordan Rose
jordan_rose at apple.com
Fri Jan 24 09:17:42 PST 2014
On Jan 24, 2014, at 2:51 , Pedro Delgado Perez <pedro.delgadoperez at mail.uca.es> wrote:
> Hi,
>
> My question is simple. Could anyone explain me what's the difference between the methods
> getResultType and getCallResultType in FunctionDecl?
>
> This is the implementation in FunctionType:
>
> 02783 QualType getResultType() const { return ResultType; }
> ...
> 02799 QualType getCallResultType(ASTContext &Context) const {2800 return getResultType().getNonLValueExprType(Context);2801 }
> And this is the definition of getNonLValueExprType:
> Determine the type of a (typically non-lvalue) expression with the specified result type.
> This routine should be used for expressions for which the return type is explicitly specified (e.g., in a cast or call) and isn't necessarily an lvalue. It removes a top-level reference (since there are no expressions of reference type) and deletes top-level cvr-qualifiers from non-class types (in C++) or all types (in C).
>
> But I am not able to understand this very well. Could anyone give me an example of the difference? Up to now, I have been using getResultType, but now I have found getCallResultType and I'm not sure what should I use.
>
I'm not 100% sure about this, but my understanding is:
You can declare your function to return "const int", but the caller is just going to get an int. Similarly, if you declare your function to return "int &", the calling expression has type "int" but is marked as an lvalue.
On the other hand, if you return "const int *", dropping the const would be incorrect. (And the same is actually true for "const int &".)
Basically, if you want to know the type the function says it's returning, use getResultType(). If you want to know the type that the CallExpr will have, use getCallResultType().
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140124/498eb5d9/attachment.html>
More information about the cfe-dev
mailing list