diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
commit | 461a67fa15370a9ec88f8f8a240bf7c123bb2029 (patch) | |
tree | 6942083d7d56bba40ec790a453ca58ad3baf6832 /test/Sema/assign.c | |
parent | 75c3240472ba6ac2669ee72ca67eb72d4e2851fc (diff) |
Diffstat (limited to 'test/Sema/assign.c')
-rw-r--r-- | test/Sema/assign.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/Sema/assign.c b/test/Sema/assign.c index 1fff77864420c..5bdfa9a3a5df9 100644 --- a/test/Sema/assign.c +++ b/test/Sema/assign.c @@ -16,3 +16,46 @@ void test3() { b[4] = 1; // expected-error {{read-only variable is not assignable}} b2[4] = 1; // expected-error {{read-only variable is not assignable}} } + +typedef struct I { + const int a; // expected-note 4{{nested data member 'a' declared const here}} \ + expected-note 6{{data member 'a' declared const here}} +} I; +typedef struct J { + struct I i; +} J; +typedef struct K { + struct J *j; +} K; + +void testI(struct I i1, struct I i2) { + i1 = i2; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}} +} +void testJ1(struct J j1, struct J j2) { + j1 = j2; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}} +} +void testJ2(struct J j, struct I i) { + j.i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}} +} +void testK1(struct K k, struct J j) { + *(k.j) = j; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}} +} +void testK2(struct K k, struct I i) { + k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}} +} + +void testI_(I i1, I i2) { + i1 = i2; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}} +} +void testJ1_(J j1, J j2) { + j1 = j2; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}} +} +void testJ2_(J j, I i) { + j.i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}} +} +void testK1_(K k, J j) { + *(k.j) = j; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}} +} +void testK2_(K k, I i) { + k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}} +} |