aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-06-04 04:11:30 +0000
committerAnders Carlsson <andersca@mac.com>2009-06-04 04:11:30 +0000
commit4d6fb501ffc0568ca5ca7266005e96a6f1273845 (patch)
treed7b02276b7a5649fd6a8f12860d2c4cf8bdfccae
parentfb6fa30a9b06670deb14f862dddbc49a12552939 (diff)
Template argument deduction for incomplete and constant array types. Doug, please review.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72844 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplateDeduction.cpp29
-rw-r--r--test/SemaTemplate/temp_class_spec.cpp30
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index c989132391..82b027c49e 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -100,6 +100,35 @@ static bool DeduceTemplateArguments(ASTContext &Context, QualType Param,
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;
}
diff --git a/test/SemaTemplate/temp_class_spec.cpp b/test/SemaTemplate/temp_class_spec.cpp
index 710fa4ada5..d516f01d7f 100644
--- a/test/SemaTemplate/temp_class_spec.cpp
+++ b/test/SemaTemplate/temp_class_spec.cpp
@@ -49,3 +49,33 @@ int is_same0[is_same<int, int>::value? 1 : -1];
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];