1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 void *test1(void) { return 0; }
5 void test2 (const struct {int a
;} *x
) {
6 // expected-note@-1 {{variable 'x' declared const here}}
9 // expected-error-re@-1 {{cannot assign to variable 'x' with const-qualified type 'const struct (unnamed struct at {{.*}}assign.c:5:19) *'}}
14 const arr b
; // expected-note {{variable 'b' declared const here}}
15 const int b2
[10]; // expected-note {{variable 'b2' declared const here}}
16 b
[4] = 1; // expected-error {{cannot assign to variable 'b' with const-qualified type 'const arr' (aka 'const int[10]')}}
17 b2
[4] = 1; // expected-error {{cannot assign to variable 'b2' with const-qualified type 'const int[10]'}}
21 const int a
; // expected-note 4{{nested data member 'a' declared const here}} \
22 expected
-note
6{{data member
'a' declared
const here
}}
31 void testI(struct I i1
, struct I i2
) {
32 i1
= i2
; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}}
34 void testJ1(struct J j1
, struct J j2
) {
35 j1
= j2
; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}}
37 void testJ2(struct J j
, struct I i
) {
38 j
.i
= i
; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
40 void testK1(struct K k
, struct J j
) {
41 *(k
.j
) = j
; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}}
43 void testK2(struct K k
, struct I i
) {
44 k
.j
->i
= i
; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
47 void testI_(I i1
, I i2
) {
48 i1
= i2
; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}}
50 void testJ1_(J j1
, J j2
) {
51 j1
= j2
; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}}
53 void testJ2_(J j
, I i
) {
54 j
.i
= i
; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
56 void testK1_(K k
, J j
) {
57 *(k
.j
) = j
; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}}
59 void testK2_(K k
, I i
) {
60 k
.j
->i
= i
; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
63 // PR39946: Recursive checking of hasConstFields caused stack overflow.
64 struct L
{ // expected-note {{definition of 'struct L' is not complete until the closing '}'}}
65 struct L field
; // expected-error {{field has incomplete type 'struct L'}}
67 void testL(struct L
*l
) {
68 *l
= 0; // expected-error {{assigning to 'struct L' from incompatible type 'int'}}
71 // Additionally, this example overflowed the stack when figuring out the field.
72 struct M1
; // expected-note {{forward declaration of 'struct M1'}}
74 //expected-note@+1 {{nested data member 'field' declared const here}}
75 const struct M1 field
; // expected-error {{field has incomplete type 'const struct M1'}}
81 void testM(struct M1
*l
) {
82 *l
= 0; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'field'}}
85 struct N1
; // expected-note {{forward declaration of 'struct N1'}}
87 struct N1 field
; // expected-error {{field has incomplete type 'struct N1'}}
93 void testN(struct N1
*l
) {
94 *l
= 0; // expected-error {{assigning to 'struct N1' from incompatible type 'int'}}