public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/65106] C99 intialization of struct with const member through a non-const pointer
Date: Thu, 19 Feb 2015 15:00:00 -0000	[thread overview]
Message-ID: <bug-65106-4-4HX2ukAXpM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65106-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Function arguments and return values don't modify existing objects, the copies
are new objects. In the assignment in your code you modify an existing object.
If it was allowed what would prevent you from doing:

  struct A a = { 1, 2 }
  struct A *ptr = &a;
  *ptr = (struct A) {10, 10};

Or simply:

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

(Clang allows both of these, despite the fact they modify a const object).


  parent reply	other threads:[~2015-02-19 15:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-18 13:28 [Bug c/65106] New: " 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 [this message]
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-4HX2ukAXpM@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: link
Be 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).