r254323 - [MS Compat] Adjust thiscall to cdecl when deducing template arguments

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 30 12:34:29 PST 2015


Author: majnemer
Date: Mon Nov 30 14:34:28 2015
New Revision: 254323

URL: http://llvm.org/viewvc/llvm-project?rev=254323&view=rev
Log:
[MS Compat] Adjust thiscall to cdecl when deducing template arguments

Function types can be extracted from member pointer types.
However, the type is not appropriate without first adjusting the calling
convention.

This fixes PR25661.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaCXX/calling-conv-compat.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=254323&r1=254322&r2=254323&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Nov 30 14:34:28 2015
@@ -1517,10 +1517,19 @@ DeduceTemplateArgumentsByTypeMatch(Sema
       if (!MemPtrArg)
         return Sema::TDK_NonDeducedMismatch;
 
+      QualType ParamPointeeType = MemPtrParam->getPointeeType();
+      if (ParamPointeeType->isFunctionType())
+        S.adjustMemberFunctionCC(ParamPointeeType, /*IsStatic=*/true,
+                                 /*IsCtorOrDtor=*/false, Info.getLocation());
+      QualType ArgPointeeType = MemPtrArg->getPointeeType();
+      if (ArgPointeeType->isFunctionType())
+        S.adjustMemberFunctionCC(ArgPointeeType, /*IsStatic=*/true,
+                                 /*IsCtorOrDtor=*/false, Info.getLocation());
+
       if (Sema::TemplateDeductionResult Result
             = DeduceTemplateArgumentsByTypeMatch(S, TemplateParams,
-                                                 MemPtrParam->getPointeeType(),
-                                                 MemPtrArg->getPointeeType(),
+                                                 ParamPointeeType,
+                                                 ArgPointeeType,
                                                  Info, Deduced,
                                                  TDF & TDF_IgnoreQualifiers))
         return Result;

Modified: cfe/trunk/test/SemaCXX/calling-conv-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/calling-conv-compat.cpp?rev=254323&r1=254322&r2=254323&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/calling-conv-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/calling-conv-compat.cpp Mon Nov 30 14:34:28 2015
@@ -370,6 +370,19 @@ X<fun_cdecl   >::p tmpl6 = &A::method_th
 X<fun_stdcall >::p tmpl7 = &A::method_stdcall;
 X<fun_fastcall>::p tmpl8 = &A::method_fastcall;
 
+// Make sure we adjust thiscall to cdecl when extracting the function type from
+// a member pointer.
+template <typename> struct Y;
+
+template <typename Fn, typename C>
+struct Y<Fn C::*> {
+  typedef Fn *p;
+};
+
+void __cdecl f_cdecl();
+Y<decltype(&A::method_thiscall)>::p tmpl9 = &f_cdecl;
+
+
 } // end namespace MemberPointers
 
 // Test that lambdas that capture nothing convert to cdecl function pointers.




More information about the cfe-commits mailing list