Pelles C forum

Pelles C => Bug reports => Topic started by: neo313 on June 09, 2014, 06:39:27 AM

Title: Inconsistent behaviour using const and anonymous structs
Post by: neo313 on June 09, 2014, 06:39:27 AM
I have stumbled upon some inconsistency when using anonymous structs in c11 mode. I believe const qualifier is ignored where it shouldn't be.



struct A
{
const int ci ;
} ;

struct B
{
struct A ;
} ;

struct C
{
struct
{
const int ci ;
} mid ;
} ;

int main(void)
{
struct A a1 = { 11 } ;
struct A a2 ;

a2 = a1 ; //warns correctly since it contains a const member ci
a1.ci = 22 ; //warns



struct B b1 = { 33 } ;
struct B b2 ;

b2 = b1 ; //doesn't warn about assigning to a const member
//6.7.2.1, paragraph 13 : The members of an anonymous structure or union
//are considered to be members of the containing structure or union.
//that would make struct B identical to struct A, yet const is ignored

b1.ci = 44 ; //warns since member is const



struct C c1 = { 55 } ;
struct C c2 ;

c2 = c1 ; //doesn't warn, this time an anonymous struct is used, same situation as with struct B
c2.mid = c1.mid ; //this time warns correctly even though(!) we are assigning anonymous structs

    return 0;
}
Title: Re: Inconsistent behaviour using const and anonymous structs
Post by: Pelle on June 09, 2014, 06:28:09 PM
Not anynomous I think: it has no name, but it has a tag. Looks fishy anyway, I will have a look...
Title: Re: Inconsistent behaviour using const and anonymous structs
Post by: neo313 on June 09, 2014, 06:34:55 PM
Thank you.

Yes, struct C does not have an anonymous struct member, my mistake.