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