Fix <rdar://problem/5733511> clang doesn't emit error for const array.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46905 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 9bd6c7e..179117e 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -904,8 +904,17 @@
}
if (t->isFunctionType())
ImpCastExprToType(e, Context.getPointerType(t));
- else if (const ArrayType *ary = t->getAsArrayType())
- ImpCastExprToType(e, Context.getPointerType(ary->getElementType()));
+ else if (const ArrayType *ary = t->getAsArrayType()) {
+ // Make sure we don't loose qualifiers when dealing with typedefs. Example:
+ // typedef int arr[10];
+ // void test2() {
+ // const arr b;
+ // b[4] = 1;
+ // }
+ QualType ELT = ary->getElementType();
+ ELT = ELT.getQualifiedType(t.getQualifiers()|ELT.getQualifiers());
+ ImpCastExprToType(e, Context.getPointerType(ELT));
+ }
}
/// UsualUnaryConversions - Performs various conversions that are common to most