public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Helmut Zeisel <HZ2012@gmx.at>
To: gcc@gcc.gnu.org
Subject: Warning: shared mutable data
Date: Fri, 17 Feb 2023 14:14:38 +0100	[thread overview]
Message-ID: <trinity-2c1fcb45-a1d8-415f-b03f-ac35a7d54b9b-1676639678378@3c-app-gmx-bs40> (raw)

Recently I read about Value-Oriented Programming
( https://accu.org/journals/overload/31/173/teodorescu/ )
There it is pointed out that sharing mutable data. i. e., code like

my_push_back(vec, vec[0]);

can lead to subtle errors. Of course GCC cannot change C++ to a language like Val that forbids such code.
From my understanding, however, sharing of mutable data can be detected by the compiler on caller side
(looking at the prototype of the function - are all shared arguments const or is there some mutable argument?)
and it might be possible to add a warning "shared mutable data".

How difficult is it to implement such a warning?

If we have such a warning, it will be possible to get some information

.) How often such code occurs in real programs?
.) Is it difficult to fix such code (e.g. by making a copy of the data before passing it to the function)
.) Is it possible to find all such possbible errors when the complete program is compiled with this warning enabled?

Even if it were not possible to detect all cases, also detecting some cases might prevent some bugs.

What do you think about adding a warning "shared mutable data" to GCC?

Helmut Zeisel



             reply	other threads:[~2023-02-17 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 13:14 Helmut Zeisel [this message]
2023-02-17 14:06 ` Jonathan Wakely
2023-02-17 15:57   ` Aw: " Helmut Zeisel

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=trinity-2c1fcb45-a1d8-415f-b03f-ac35a7d54b9b-1676639678378@3c-app-gmx-bs40 \
    --to=hz2012@gmx.at \
    --cc=gcc@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).