[PATCH] Ignore calling conventions when checking function template specializations
Reid Kleckner
rnk at google.com
Fri Aug 30 20:09:56 PDT 2013
Hi rsmith,
Calling conventions are inherited during decl merging. Before this
change, deduction would fail due to a type mismatch between the template
and the specialization. This change adjusts the CCs to match before
deduction, and lets the decl merging logic diagnose mismatch or inherit
the CC from the template.
This allows specializations of static member function templates in the
Microsoft C++ ABI.
http://llvm-reviews.chandlerc.com/D1570
Files:
lib/Sema/SemaTemplate.cpp
test/SemaCXX/decl-microsoft-call-conv.cpp
Index: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6403,18 +6403,28 @@
// it will be a static member function until we know which template it
// specializes), so adjust it now assuming it specializes this template.
QualType FT = FD->getType();
+ const FunctionProtoType *FPT = FT->castAs<FunctionProtoType>();
+ FunctionDecl *TmplFD = FunTmpl->getTemplatedDecl();
if (FD->isConstexpr()) {
- CXXMethodDecl *OldMD =
- dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
+ CXXMethodDecl *OldMD = dyn_cast<CXXMethodDecl>(TmplFD);
if (OldMD && OldMD->isConst()) {
- const FunctionProtoType *FPT = FT->castAs<FunctionProtoType>();
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
EPI.TypeQuals |= Qualifiers::Const;
FT = Context.getFunctionType(FPT->getResultType(), FPT->getArgTypes(),
EPI);
}
}
+ // Ignore differences in calling convention until decl merging.
+ const FunctionProtoType *TmplFT =
+ TmplFD->getType()->castAs<FunctionProtoType>();
+ if (FPT->getCallConv() != TmplFT->getCallConv()) {
+ FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+ EPI.ExtInfo = EPI.ExtInfo.withCallingConv(TmplFT->getCallConv());
+ FT = Context.getFunctionType(FPT->getResultType(), FPT->getArgTypes(),
+ EPI);
+ }
+
// C++ [temp.expl.spec]p11:
// A trailing template-argument can be left unspecified in the
// template-id naming an explicit function template specialization
Index: test/SemaCXX/decl-microsoft-call-conv.cpp
===================================================================
--- test/SemaCXX/decl-microsoft-call-conv.cpp
+++ test/SemaCXX/decl-microsoft-call-conv.cpp
@@ -144,3 +144,19 @@
// expected-error at +2 {{stdcall and cdecl attributes are not compatible}}
// expected-error at +1 {{fastcall and cdecl attributes are not compatible}}
void __cdecl __cdecl __stdcall __cdecl __fastcall multi_cc(int x);
+
+template <typename T> void __stdcall StdcallTemplate(T) {}
+template <> void StdcallTemplate<int>(int) {}
+template <> void __stdcall StdcallTemplate<short>(short) {}
+
+// FIXME: Note the template, not the implicit instantiation.
+// expected-error at +2 {{function declared 'cdecl' here was previously declared 'stdcall}}
+// expected-note at +1 {{previous declaration is here}}
+template <> void __cdecl StdcallTemplate<long>(long) {}
+
+struct ExactlyInt {
+ template <typename T> static int cast_to_int(T) {
+ return T::this_is_not_an_int();
+ }
+};
+template <> inline int ExactlyInt::cast_to_int<int>(int x) { return x; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1570.1.patch
Type: text/x-patch
Size: 2861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130830/f6ee38a8/attachment.bin>
More information about the cfe-commits
mailing list