]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/5733511> clang doesn't emit error for const array.
authorSteve Naroff <snaroff@apple.com>
Sat, 9 Feb 2008 16:59:44 +0000 (16:59 +0000)
committerSteve Naroff <snaroff@apple.com>
Sat, 9 Feb 2008 16:59:44 +0000 (16:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46905 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaExpr.cpp
test/Sema/assign.c

index 9bd6c7e44c76be7893276afabee4a720d7a47121..179117e96e6c17815839dbcde6008c0eb771a938 100644 (file)
@@ -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
index b94d5835ee8bdf4fa93ea38aedd99452c2e33c14..4ddb25a94afba95293d6e2917f63fdc0d95fb65d 100644 (file)
@@ -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}}
+}