[cfe-commits] r46905 - in /cfe/trunk: Sema/SemaExpr.cpp test/Sema/assign.c
Steve Naroff
snaroff at apple.com
Sat Feb 9 08:59:45 PST 2008
Author: snaroff
Date: Sat Feb 9 10:59:44 2008
New Revision: 46905
URL: http://llvm.org/viewvc/llvm-project?rev=46905&view=rev
Log:
Fix <rdar://problem/5733511> clang doesn't emit error for const array.
Modified:
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/assign.c
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=46905&r1=46904&r2=46905&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sat Feb 9 10:59:44 2008
@@ -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
Modified: cfe/trunk/test/Sema/assign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/assign.c?rev=46905&r1=46904&r2=46905&view=diff
==============================================================================
--- cfe/trunk/test/Sema/assign.c (original)
+++ cfe/trunk/test/Sema/assign.c Sat Feb 9 10:59:44 2008
@@ -5,3 +5,11 @@
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}}
+}
More information about the cfe-commits
mailing list