aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-17 18:45:21 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-17 18:45:21 +0000
commit9dadd94e1c17fa030d1f88d8f2113ff59ccc6714 (patch)
tree1a15311692d26eaa3a1928dd14dd235b9d248be7
parent33f992425213f381fc503699b26ee8cf9b60494e (diff)
Teach ASTContext::getUnqualifiedArrayType() how to look through
typedefs. As a drive-by, teach hit how to build VLA types, since those will eventually be supported in C++. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103958 91177308-0d34-0410-b5e6-96231b3b80d8
-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);
+ }
+}