Improve template argument deduction for array types, so that a parameter

  const T

can be matched with, e.g.,

  volatile int [5]




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76773 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index ac4e4b9..4e6d0f4 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -341,6 +341,14 @@
         = Param->getAsTemplateTypeParmType()) {
     unsigned Index = TemplateTypeParm->getIndex();
 
+    // If the argument type is an array type, move the qualifiers up to the
+    // top level, so they can be matched with the qualifiers on the parameter.
+    // FIXME: address spaces, ObjC GC qualifiers
+    QualType ArgElementType = Arg;
+    while (const ArrayType *ArgArray = ArgElementType->getAs<ArrayType>())
+      ArgElementType = ArgArray->getElementType();
+    Arg = Arg.getWithAdditionalQualifiers(ArgElementType.getCVRQualifiers());
+                                          
     // The argument type can not be less qualified than the parameter
     // type.
     if (Param.isMoreQualifiedThan(Arg) && !(TDF & TDF_IgnoreQualifiers)) {