forked from OSchip/llvm-project
Fix <rdar://problem/5733511> clang doesn't emit error for const array.
llvm-svn: 46905
This commit is contained in:
parent
a62f3e1352
commit
45173e0ac0
|
@ -904,8 +904,17 @@ void Sema::DefaultFunctionArrayConversion(Expr *&e) {
|
|||
}
|
||||
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
|
||||
|
|
|
@ -5,3 +5,11 @@ void *test1(void) { return 0; }
|
|||
void test2 (const struct {int a;} *x) {
|
||||
x->a = 10; // expected-error {{read-only variable is not assignable}}
|
||||
}
|
||||
|
||||
typedef int arr[10];
|
||||
void test3() {
|
||||
const arr b;
|
||||
const int b2[10];
|
||||
b[4] = 1; // expected-error {{read-only variable is not assignable}}
|
||||
b2[4] = 1; // expected-error {{read-only variable is not assignable}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue