diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-17 18:45:21 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-17 18:45:21 +0000 |
commit | 3b05bdba5ad007d21c8b605d0a6a5beaf847f89c (patch) | |
tree | b13607f8c76bf2ff89815197f8b288330e168266 | |
parent | fd5c3a34e3cd5f0556f597b2aec201bca1b101cf (diff) | |
download | bcm5719-llvm-3b05bdba5ad007d21c8b605d0a6a5beaf847f89c.tar.gz bcm5719-llvm-3b05bdba5ad007d21c8b605d0a6a5beaf847f89c.zip |
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++.
llvm-svn: 103958
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 19 | ||||
-rw-r--r-- | clang/test/SemaCXX/references.cpp | 15 |
2 files changed, 29 insertions, 5 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index d0e4c02b913..cd567a6142e 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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/clang/test/SemaCXX/references.cpp b/clang/test/SemaCXX/references.cpp index e40ea01a9b9..a7aafe41c39 100644 --- a/clang/test/SemaCXX/references.cpp +++ b/clang/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); + } +} |