[cfe-commits] r76773 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/temp_class_spec.cpp
Douglas Gregor
dgregor at apple.com
Wed Jul 22 13:02:26 PDT 2009
Author: dgregor
Date: Wed Jul 22 15:02:25 2009
New Revision: 76773
URL: http://llvm.org/viewvc/llvm-project?rev=76773&view=rev
Log:
Improve template argument deduction for array types, so that a parameter
const T
can be matched with, e.g.,
volatile int [5]
Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.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=76773&r1=76772&r2=76773&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jul 22 15:02:25 2009
@@ -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)) {
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=76773&r1=76772&r2=76773&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Jul 22 15:02:25 2009
@@ -758,6 +758,7 @@
// which case the cv-qualifiers are ignored.
//
// The same rule applies to function types.
+ // FIXME: what about address-space and Objective-C GC qualifiers?
if (!Result.isNull() && T.getCVRQualifiers() &&
!Result->isFunctionType() && !Result->isReferenceType())
Result = Result.getWithAdditionalQualifiers(T.getCVRQualifiers());
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=76773&r1=76772&r2=76773&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_class_spec.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_class_spec.cpp Wed Jul 22 15:02:25 2009
@@ -32,6 +32,35 @@
int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1];
int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1];
+template<typename T>
+struct is_const {
+ static const bool value = false;
+};
+
+template<typename T>
+struct is_const<const T> {
+ static const bool value = true;
+};
+
+int is_const0[is_const<int>::value? -1 : 1];
+int is_const1[is_const<const int>::value? 1 : -1];
+int is_const2[is_const<const volatile int>::value? 1 : -1];
+
+template<typename T>
+struct is_volatile {
+ static const bool value = false;
+};
+
+template<typename T>
+struct is_volatile<volatile T> {
+ static const bool value = true;
+};
+
+int is_volatile0[is_volatile<int>::value? -1 : 1];
+int is_volatile1[is_volatile<volatile int>::value? 1 : -1];
+int is_volatile2[is_volatile<const volatile int>::value? 1 : -1];
+int is_volatile3[is_volatile<volatile char[3]>::value? 1 : -1];
+
template<typename T, typename U>
struct is_same {
static const bool value = false;
More information about the cfe-commits
mailing list