]> granicus.if.org Git - clang/commitdiff
Take into consideration calling convention when processing specializations.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 10 Dec 2013 00:59:31 +0000 (00:59 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 10 Dec 2013 00:59:31 +0000 (00:59 +0000)
This fixes pr18141.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196855 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaType.cpp
test/SemaCXX/decl-microsoft-call-conv.cpp

index 0778b1b235e3d170e82adb346f9d4ef0f8d56b3a..67ad469c1c660a16e8970d663918b2985859c5d0 100644 (file)
@@ -2570,6 +2570,11 @@ public:
   /// function type typedefs and typename template arguments.
   void adjustMemberFunctionCC(QualType &T, bool IsStatic);
 
+  // Check if there is an explicit attribute, but only look through parens.
+  // The intent is to look for an attribute on the current declarator, but not
+  // one that came from a typedef.
+  bool hasExplicitCallingConv(QualType &T);
+
   /// Get the outermost AttributedType node that sets a calling convention.
   /// Valid types should not have multiple attributes with different CCs.
   const AttributedType *getCallingConvAttributedType(QualType T) const;
index 20a3d28331478c2856280e40e583f40c3fbc34e0..b134f6ea51070a3b34dcacc586fc5b77fa5bb8a1 100644 (file)
@@ -6654,7 +6654,10 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
            I != E; ++I) {
       NamedDecl *D = (*I)->getUnderlyingDecl();
       if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
-        if (Context.hasSameType(Function->getType(), Method->getType())) {
+        QualType Adjusted = Function->getType();
+        if (!hasExplicitCallingConv(Adjusted))
+          Adjusted = adjustCCAndNoReturn(Adjusted, Method->getType());
+        if (Context.hasSameType(Adjusted, Method->getType())) {
           Instantiation = Method;
           InstantiatedFrom = Method->getInstantiatedFromMemberFunction();
           MSInfo = Method->getMemberSpecializationInfo();
index 514a0fa30d104c7229fb66d56feab598ddd11336..e6a49f5d3f3d27cf05c47ff2380ce140cad834e0 100644 (file)
@@ -4595,6 +4595,16 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state,
   return true;
 }
 
+bool Sema::hasExplicitCallingConv(QualType &T) {
+  QualType R = T.IgnoreParens();
+  while (const AttributedType *AT = dyn_cast<AttributedType>(R)) {
+    if (AT->isCallingConv())
+      return true;
+    R = AT->getModifiedType().IgnoreParens();
+  }
+  return false;
+}
+
 void Sema::adjustMemberFunctionCC(QualType &T, bool IsStatic) {
   FunctionTypeUnwrapper Unwrapped(*this, T);
   const FunctionType *FT = Unwrapped.get();
@@ -4611,15 +4621,8 @@ void Sema::adjustMemberFunctionCC(QualType &T, bool IsStatic) {
   if (CurCC != FromCC || FromCC == ToCC)
     return;
 
-  // Check if there was an explicit attribute, but only look through parens.
-  // The intent is to look for an attribute on the current declarator, but not
-  // one that came from a typedef.
-  QualType R = T.IgnoreParens();
-  while (const AttributedType *AT = dyn_cast<AttributedType>(R)) {
-    if (AT->isCallingConv())
-      return;
-    R = AT->getModifiedType().IgnoreParens();
-  }
+  if (hasExplicitCallingConv(T))
+    return;
 
   FT = Context.adjustFunctionType(FT, FT->getExtInfo().withCallingConv(ToCC));
   QualType Wrapped = Unwrapped.wrap(*this, FT);
index fd20ae234ec53b0035815bafd8173f657c8bc0c2..fa782ead3495dd080266a0441fb52723344e3e0e 100644 (file)
@@ -203,3 +203,29 @@ namespace test6 {
     zed(&foo::bar);
   }
 }
+
+namespace test7 {
+  template <typename T>
+  struct S {
+    void f(T t) {
+      t = 42;
+    }
+  };
+  template<> void S<void*>::f(void*);
+  void g(S<void*> s, void* p) {
+    s.f(p);
+  }
+}
+
+namespace test8 {
+  template <typename T>
+  struct S {
+    void f(T t) { // expected-note {{previous declaration is here}}
+      t = 42; // expected-error {{assigning to 'void *' from incompatible type 'int'}}
+    }
+  };
+  template<> void __cdecl S<void*>::f(void*); // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
+  void g(S<void*> s, void* p) {
+    s.f(p); // expected-note {{in instantiation of member function 'test8::S<void *>::f' requested here}}
+  }
+}