assign.c 556 B

123456789101112131415161718
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. void *test1(void) { return 0; }
  3. void test2 (const struct {int a;} *x) {
  4. // expected-note@-1 {{variable 'x' declared const here}}
  5. x->a = 10;
  6. // expected-error-re@-1 {{cannot assign to variable 'x' with const-qualified type 'const struct (anonymous struct at {{.*}}assign.c:5:19) *'}}
  7. }
  8. typedef int arr[10];
  9. void test3() {
  10. const arr b;
  11. const int b2[10];
  12. b[4] = 1; // expected-error {{read-only variable is not assignable}}
  13. b2[4] = 1; // expected-error {{read-only variable is not assignable}}
  14. }