forked from OSchip/llvm-project
Template argument deduction for incomplete and constant array types. Doug, please review.
llvm-svn: 72844
This commit is contained in:
parent
43c52cdc29
commit
35533d11b3
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue