Difference between getResultType adn getCallResultType

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](http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8)   [QualType](http://clang.llvm.org/doxygen/classclang_1_1QualType.html) [getResultType](http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8)() const { return ResultType; }
...
[02799](http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85)   [QualType](http://clang.llvm.org/doxygen/classclang_1_1QualType.html) [getCallResultType](http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85)([ASTContext](http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html) &[Context](http://clang.llvm.org/doxygen/ASTMatchFinder_8cpp.html#a779280869b9fac47a9bc391e7709171f)) const {2800     return getResultType().[getNonLValueExprType](http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c)(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.

Thanks in advance,

Pedro.

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

We should rename ‘getResultType’ to ‘getReturnType’ to clarify this (and to generally follow the standard terminology). This has been on my TODO list for a long time, but there’s always been something more pressing to do…

    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 <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8&gt; QualType <http://clang.llvm.org/doxygen/classclang_1_1QualType.html&gt; getResultType <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8&gt;\(\) const{return ResultType; }

    ...
    02799 <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85&gt; QualType <http://clang.llvm.org/doxygen/classclang_1_1QualType.html&gt; getCallResultType <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85&gt;\(ASTContext <http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html&gt; &Context <http://clang.llvm.org/doxygen/ASTMatchFinder_8cpp.html#a779280869b9fac47a9bc391e7709171f&gt;\) const{2800return getResultType().getNonLValueExprType <http://clang.llvm.org/doxygen/classclang_1_1QualType.html\#a89e3ea65c009b7a0ea76edc56076107c&gt;\(Context\);2801 }

    And this is the definition ofgetNonLValueExprType
    <http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c&gt;:
    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().

We should rename 'getResultType' to 'getReturnType' to clarify this (and to generally follow the standard terminology). This has been on my TODO list for a long time, but there's always been something more pressing to do...

I'll take a look into this shortly, it's very much in line with the other terminology fixes we've been working on lately. Will deprecate and keep the old version around for external modules.

Richard, do you see any other terminology fixes we could get done while I have the refactoring setup primed?

Alp.

    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 <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8&gt; QualType <http://clang.llvm.org/doxygen/classclang_1_1QualType.html&gt; getResultType <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8&gt;\(\) const{return ResultType; }

    ...
    02799 <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85&gt; QualType <http://clang.llvm.org/doxygen/classclang_1_1QualType.html&gt; getCallResultType <http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85&gt;\(ASTContext <http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html&gt; &Context <http://clang.llvm.org/doxygen/ASTMatchFinder_8cpp.html#a779280869b9fac47a9bc391e7709171f&gt;\) const{2800return getResultType().getNonLValueExprType <http://clang.llvm.org/doxygen/classclang_1_1QualType.html\#a89e3ea65c009b7a0ea76edc56076107c&gt;\(Context\);2801 }

    And this is the definition ofgetNonLValueExprType
    <http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c&gt;:
    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().

We should rename 'getResultType' to 'getReturnType' to clarify this (and to generally follow the standard terminology). This has been on my TODO list for a long time, but there's always been something more pressing to do...

Done in r200082

Alp.