[cfe-commits] r72844 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/temp_class_spec.cpp

Anders Carlsson andersca at mac.com
Wed Jun 3 21:11:31 PDT 2009


Author: andersca
Date: Wed Jun  3 23:11:30 2009
New Revision: 72844

URL: http://llvm.org/viewvc/llvm-project?rev=72844&view=rev
Log:
Template argument deduction for incomplete and constant array types. Doug, please review.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/temp_class_spec.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=72844&r1=72843&r2=72844&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jun  3 23:11:30 2009
@@ -100,6 +100,35 @@
                                      Deduced);
     }
       
+    case Type::IncompleteArray: {
+      const IncompleteArrayType *IncompleteArrayArg = 
+        Context.getAsIncompleteArrayType(Arg);
+      if (!IncompleteArrayArg)
+        return false;
+      
+      return DeduceTemplateArguments(Context,
+                     Context.getAsIncompleteArrayType(Param)->getElementType(),
+                                     IncompleteArrayArg->getElementType(),
+                                     Deduced);
+    }
+    
+    case Type::ConstantArray: {
+      const ConstantArrayType *ConstantArrayArg = 
+        Context.getAsConstantArrayType(Arg);
+      if (!ConstantArrayArg)
+        return false;
+      
+      const ConstantArrayType *ConstantArrayParm = 
+        Context.getAsConstantArrayType(Param);
+      if (ConstantArrayArg->getSize() != ConstantArrayParm->getSize())
+        return false;
+      
+      return DeduceTemplateArguments(Context,
+                                     ConstantArrayParm->getElementType(),
+                                     ConstantArrayArg->getElementType(),
+                                     Deduced);
+    }
+
     default:
       break;
   }

Modified: cfe/trunk/test/SemaTemplate/temp_class_spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_class_spec.cpp?rev=72844&r1=72843&r2=72844&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_class_spec.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_class_spec.cpp Wed Jun  3 23:11:30 2009
@@ -49,3 +49,33 @@
 int is_same1[is_same<int, INT>::value? 1 : -1];
 int is_same2[is_same<const int, int>::value? -1 : 1];
 int is_same3[is_same<int_ptr, int>::value? -1 : 1];
+
+template<typename T>
+struct is_incomplete_array {
+  static const bool value = false;
+};
+
+template<typename T>
+struct is_incomplete_array<T[]> {
+  static const bool value = true;
+};
+
+int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
+int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
+int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
+int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
+
+template<typename T>
+struct is_array_with_4_elements {
+  static const bool value = false;
+};
+
+template<typename T>
+struct is_array_with_4_elements<T[4]> {
+  static const bool value = true;
+};
+
+int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
+int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
+int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
+int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];





More information about the cfe-commits mailing list