<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jan 24, 2014, at 2:51 , Pedro Delgado Perez <<a href="mailto:pedro.delgadoperez@mail.uca.es">pedro.delgadoperez@mail.uca.es</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">

<div><p>Hi,</p><p>My question is simple. Could anyone explain me what's the difference between the methods<br>
getResultType and getCallResultType in FunctionDecl?</p><p>This is the implementation in FunctionType:</p>
<pre class="fragment"><a class="code" href="http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8">02783</a>   <a class="code" href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a> <a class="code" href="http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#aafa453cd7e81a7c3d6c61f261e68afe8">getResultType</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> ResultType; }<br>...<br><a class="code" href="http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85">02799</a>   <a class="code" href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a> <a class="code" title="Determine the type of an expression that calls a function of this type." href="http://clang.llvm.org/doxygen/classclang_1_1FunctionType.html#a5f8df0258bcf7281e7055ea01dbd8f85">getCallResultType</a>(<a class="code" title="Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ..." href="http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html">ASTContext</a> &<a class="code" href="http://clang.llvm.org/doxygen/ASTMatchFinder_8cpp.html#a779280869b9fac47a9bc391e7709171f">Context</a>)<span class="keyword"> const </span>{2800     <span class="keywordflow">return</span> getResultType().<a class="code" title="Determine the type of a (typically non-lvalue) expression with the specified result type..." href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c">getNonLValueExprType</a>(Context);2801   }</pre><p>And this is the definition of<a class="code" title="Determine the type of a (typically non-lvalue) expression with the specified result type..." href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html#a89e3ea65c009b7a0ea76edc56076107c"> getNonLValueExprType</a>:<br>
<span style="font-size: 10pt;">Determine the type of a (typically non-lvalue) expression with the specified result type. </span><br>
<span style="font-size: 10pt;">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). </span></p><p>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.</p></div></blockquote></div><div>I'm not 100% sure about this, but my understanding is:</div><div><br></div><div>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.</div><br><div>On the other hand, if you return "const int *", dropping the const would be incorrect. (And the same is actually true for "const int &".)</div><div><br></div><div>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().</div><div><br></div><div>Jordan</div></body></html>