Merging r196050:
------------------------------------------------------------------------
r196050 | rafael | 2013-12-01 08:54:29 -0800 (Sun, 01 Dec 2013) | 5 lines

Handle CC and NoReturn when instantiating members of class templates.

Before we were considering them only when instantiating templates.

This fixes pr18033.
------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_34@196057 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index 56df8ba..8d66ff6 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -3501,6 +3501,28 @@
                                          Specialization, Info, &OriginalCallArgs);
 }
 
+QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,
+                                   QualType FunctionType) {
+  if (ArgFunctionType.isNull())
+    return ArgFunctionType;
+
+  const FunctionProtoType *FunctionTypeP =
+      FunctionType->castAs<FunctionProtoType>();
+  CallingConv CC = FunctionTypeP->getCallConv();
+  bool NoReturn = FunctionTypeP->getNoReturnAttr();
+  const FunctionProtoType *ArgFunctionTypeP =
+      ArgFunctionType->getAs<FunctionProtoType>();
+  if (ArgFunctionTypeP->getCallConv() == CC &&
+      ArgFunctionTypeP->getNoReturnAttr() == NoReturn)
+    return ArgFunctionType;
+
+  FunctionType::ExtInfo EI = ArgFunctionTypeP->getExtInfo().withCallingConv(CC);
+  EI = EI.withNoReturn(NoReturn);
+  ArgFunctionTypeP =
+      cast<FunctionProtoType>(Context.adjustFunctionType(ArgFunctionTypeP, EI));
+  return QualType(ArgFunctionTypeP, 0);
+}
+
 /// \brief Deduce template arguments when taking the address of a function
 /// template (C++ [temp.deduct.funcaddr]) or matching a specialization to
 /// a template.
@@ -3538,23 +3560,8 @@
   TemplateParameterList *TemplateParams
     = FunctionTemplate->getTemplateParameters();
   QualType FunctionType = Function->getType();
-  if (!InOverloadResolution && !ArgFunctionType.isNull()) {
-    const FunctionProtoType *FunctionTypeP =
-        FunctionType->castAs<FunctionProtoType>();
-    CallingConv CC = FunctionTypeP->getCallConv();
-    bool NoReturn = FunctionTypeP->getNoReturnAttr();
-    const FunctionProtoType *ArgFunctionTypeP =
-        ArgFunctionType->getAs<FunctionProtoType>();
-    if (ArgFunctionTypeP->getCallConv() != CC ||
-        ArgFunctionTypeP->getNoReturnAttr() != NoReturn) {
-      FunctionType::ExtInfo EI =
-          ArgFunctionTypeP->getExtInfo().withCallingConv(CC);
-      EI = EI.withNoReturn(NoReturn);
-      ArgFunctionTypeP = cast<FunctionProtoType>(
-          Context.adjustFunctionType(ArgFunctionTypeP, EI));
-      ArgFunctionType = QualType(ArgFunctionTypeP, 0);
-    }
-  }
+  if (!InOverloadResolution)
+    ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, FunctionType);
 
   // Substitute any explicit template arguments.
   LocalInstantiationScope InstScope(*this);