<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Nov 19, 2013 at 8:43 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The previous patches tried to deduce the correct function type. I now<br>

don't think that is possible in general. Consider<br>
<br>
class foo {<br>
    template <typename T> static void bar(T v);<br>
};<br>
extern template void foo::bar(const void *);<br>
<br>
We will only now that bar is static after a lookup, so it looks like<br>
we have to handle this in the template instantiation code. This also<br>
makes me suspicious of the previous users of FreeFunction always being<br>
correct.<br></blockquote><div><br></div><div>Yes, the calling convention can always change at decl merging time due to static methods or declarations with explicit conventions.  Templates make that redeclaration lookup complicated.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The attached patch reverts my previous two (but not the tests) and<br>
instead handles the issue in DeduceTemplateArguments.<br></blockquote><div><br></div><div><div>+  if (!InOverloadResolution && !ArgFunctionType.isNull()) {</div><div>+    CallingConv CC = FunctionType->getAs<FunctionProtoType>()->getCallConv();</div>
<div>+    const FunctionProtoType *ArgFunctionTypeP =</div><div>+        ArgFunctionType->getAs<FunctionProtoType>();</div><div><br></div><div><div>Use castAs<> if you're going to dereference unconditionally.</div>
</div><div><br></div><div>+    if (ArgFunctionTypeP->getCallConv() != CC) {</div><div>+      FunctionType::ExtInfo EI =</div><div>+          ArgFunctionTypeP->getExtInfo().withCallingConv(CC);</div><div>+      ArgFunctionTypeP = cast<FunctionProtoType>(</div>
<div>+          Context.adjustFunctionType(ArgFunctionTypeP, EI));</div><div>+      ArgFunctionType = QualType(ArgFunctionTypeP, 0);</div><div>+    }</div><div>+  }</div></div><div><br></div><div>This looks like the logic I added to Sema::CheckFunctionTemplateSpecialization() in r190377.  If you add this, can we remove it?  If not, can we share it?  See also the related ExactlyInt test case.</div>
</div></div></div>