public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "andrii.riabushenko at barclays dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65106] New: C99 intialization of struct with const member through a non-const pointer Date: Wed, 18 Feb 2015 13:28:00 -0000 [thread overview] Message-ID: <bug-65106-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2015-02-18 13:28 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-18 13:28 andrii.riabushenko at barclays dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-65106-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).