[cfe-dev] Difference between getResultType adn getCallResultType

Alp Toker alp at nuanti.com
Sat Jan 25 09:05:27 PST 2014


On 25/01/2014 01:24, Richard Smith wrote:
> On Fri Jan 24 2014 at 9:20:44 AM, Jordan Rose <jordan_rose at apple.com 
> <mailto:jordan_rose at apple.com>> wrote:
>
>
>     On Jan 24, 2014, at 2:51 , Pedro Delgado Perez
>     <pedro.delgadoperez at mail.uca.es
>     <mailto: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  <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{2800return  getResultType().getNonLValueExprType  <http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c>(Context);2801   }
>>
>>     And this is the definition ofgetNonLValueExprType
>>     <http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c>:
>>     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.


>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-dev mailing list