public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65106] New: C99 intialization of struct with const member through a non-const pointer
@ 2015-02-18 13:28 andrii.riabushenko at barclays dot com
  2015-02-18 14:27 ` [Bug c/65106] " joseph at codesourcery dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andrii.riabushenko at barclays dot com @ 2015-02-18 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65106

            Bug ID: 65106
           Summary: C99 intialization of struct with const member through
                    a non-const pointer
           Product: gcc
           Version: 4.9.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrii.riabushenko at barclays dot com

I noticed that such C99 code is valid in Clang, but not in GCC:

#include<stdlib.h>

struct A {
  int x;
  const int y;
}

struct A* make() 
{
  struct A *ptr = malloc(sizeof(struct A));
  *ptr = (struct A) {10, 10};
}

I find this language construct rather useful. I quickly scanned the C standard
and I can't find the evidence that is actually prohibited. There is a
difference between assignment a const member (ptr->y = 10) that should be
prohibited and actual struct initialization through non-const pointer. For some
reason GCC does not distinguish these 2 cases.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-10-22  9:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 13:28 [Bug c/65106] New: C99 intialization of struct with const member through a non-const pointer andrii.riabushenko at barclays dot com
2015-02-18 14:27 ` [Bug c/65106] " joseph at codesourcery dot com
2015-02-19 14:51 ` andrii.riabushenko at barclays dot com
2015-02-19 15:00 ` redi at gcc dot gnu.org
2015-10-22  9:17 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).