[patch] Further issues when thiscall is the default for methods.

Reid Kleckner rnk at google.com
Tue Nov 19 10:43:08 PST 2013


On Tue, Nov 19, 2013 at 8:43 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> The previous patches tried to deduce the correct function type. I now
> don't think that is possible in general. Consider
>
> class foo {
>     template <typename T> static void bar(T v);
> };
> extern template void foo::bar(const void *);
>
> We will only now that bar is static after a lookup, so it looks like
> we have to handle this in the template instantiation code. This also
> makes me suspicious of the previous users of FreeFunction always being
> correct.
>

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.

The attached patch reverts my previous two (but not the tests) and
> instead handles the issue in DeduceTemplateArguments.
>

+  if (!InOverloadResolution && !ArgFunctionType.isNull()) {
+    CallingConv CC =
FunctionType->getAs<FunctionProtoType>()->getCallConv();
+    const FunctionProtoType *ArgFunctionTypeP =
+        ArgFunctionType->getAs<FunctionProtoType>();

Use castAs<> if you're going to dereference unconditionally.

+    if (ArgFunctionTypeP->getCallConv() != CC) {
+      FunctionType::ExtInfo EI =
+          ArgFunctionTypeP->getExtInfo().withCallingConv(CC);
+      ArgFunctionTypeP = cast<FunctionProtoType>(
+          Context.adjustFunctionType(ArgFunctionTypeP, EI));
+      ArgFunctionType = QualType(ArgFunctionTypeP, 0);
+    }
+  }

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131119/ec426825/attachment.html>


More information about the cfe-commits mailing list