]> granicus.if.org Git - clang/commitdiff
Teach ASTContext::getUnqualifiedArrayType() how to look through
authorDouglas Gregor <dgregor@apple.com>
Mon, 17 May 2010 18:45:21 +0000 (18:45 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 17 May 2010 18:45:21 +0000 (18:45 +0000)
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

lib/AST/ASTContext.cpp
test/SemaCXX/references.cpp

index d0e4c02b9137d199278a06df87f60d80dca598f9..cd567a6142e0a66ce88cfdd7c451d2a3a38687a7 100644 (file)
@@ -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());
index e40ea01a9b99165be41c7d6bd728c181cb330169..a7aafe41c392d754918dd5e00901a4ec803fe984 100644 (file)
@@ -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);
+  }
+}