aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/AST/ASTContext.cpp19
-rw-r--r--test/SemaCXX/references.cpp15
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index d0e4c02b91..cd567a6142 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2335,26 +2335,35 @@ CanQualType ASTContext::getCanonicalType(QualType T) {
QualType ASTContext::getUnqualifiedArrayType(QualType T,
Qualifiers &Quals) {
Quals = T.getQualifiers();
- if (!isa<ArrayType>(T)) {
+ const ArrayType *AT = getAsArrayType(T);
+ if (!AT) {
return T.getUnqualifiedType();
}
- const ArrayType *AT = cast<ArrayType>(T);
QualType Elt = AT->getElementType();
QualType UnqualElt = getUnqualifiedArrayType(Elt, Quals);
if (Elt == UnqualElt)
return T;
- if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(T)) {
+ if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
return getConstantArrayType(UnqualElt, CAT->getSize(),
CAT->getSizeModifier(), 0);
}
- if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(T)) {
+ if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) {
return getIncompleteArrayType(UnqualElt, IAT->getSizeModifier(), 0);
}
- const DependentSizedArrayType *DSAT = cast<DependentSizedArrayType>(T);
+ if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(AT)) {
+ return getVariableArrayType(UnqualElt,
+ VAT->getSizeExpr() ?
+ VAT->getSizeExpr()->Retain() : 0,
+ VAT->getSizeModifier(),
+ VAT->getIndexTypeCVRQualifiers(),
+ VAT->getBracketsRange());
+ }
+
+ const DependentSizedArrayType *DSAT = cast<DependentSizedArrayType>(AT);
return getDependentSizedArrayType(UnqualElt, DSAT->getSizeExpr()->Retain(),
DSAT->getSizeModifier(), 0,
SourceRange());
diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp
index e40ea01a9b..a7aafe41c3 100644
--- a/test/SemaCXX/references.cpp
+++ b/test/SemaCXX/references.cpp
@@ -115,3 +115,18 @@ void test10() {
int &c = ev.x; // expected-error{{non-const reference cannot bind to vector element}}
const int &d = ev.x;
}
+
+namespace PR7149 {
+ template<typename T> struct X0
+ {
+ T& first;
+ X0(T& p1) : first(p1) { }
+ };
+
+
+ void f()
+ {
+ int p1[1];
+ X0< const int[1]> c(p1);
+ }
+}