From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id AA0233858C31 for ; Fri, 17 Feb 2023 14:06:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA0233858C31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x534.google.com with SMTP id h14so4941287edz.10 for ; Fri, 17 Feb 2023 06:06:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Tj28nrm1XAWGWAjWL80twfUTAERWpgrTI5e8lTQpcS8=; b=gloFqwc4I9ciPDxaIbcrNqeoNfHxjP3nG4lKB549W32rV5LA9OT8UMBRtQhCeCbZwN xFdpzPZ/lhn7MBBGTOa7VJ72hN468tXEXk4RoSJBShwDC/sA8sSfxLHvC2sCF0B71G6R mZXeG1JxynmgmmB1st8h+Sn/wvTkK8kDSbo2/KhayeAcmJ+Bcs5h/F48kR0skp4uAjuU iKR/7FqM7FR/8MKGO8v9m9C6pvmtf06DLbFkALZPHZULNwycdB24bL7Ik1z+7P1pEwJz crNhxiWRfTqJT098D++M8zwPpKDeBlglN8KRSs6Te5xybB2wCB4JvuGOO5TfFLJGDM40 oFGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Tj28nrm1XAWGWAjWL80twfUTAERWpgrTI5e8lTQpcS8=; b=nSjLMu2VTAYUbSsLy94b705+Vast/zkverAOcWGjcPRoPWoCFX8SZ3SsF0HwFmbMMI v6msp7qOZ4Q6KfIMTUCy4DSWnV85vP7w40ddElZ/JP4FvN4RL/vAtVctnHJlZ9N3Fxr7 Y5fWd9TAyYBh5gihk9g69q7du2LExLBQ2CPxIS61r0k+ED1Gr0fFQc2MonTkYq/lU9GD V00x84k/MisHATkxWV1rNFr/6uGTi1Jr4ygf5kQ0r3rG9aWJpyD3ngi2yZW0nGW4FLh7 yq+tXi5KjGvv9Fdb2leSIZ7DJhgjpWHK5tcDtMnfa2YNw0FCNvZw5ykzs9uQmxxvltfk BSwQ== X-Gm-Message-State: AO0yUKVxmccNYGHeprme6VjApXPU9b3o/M+J4w0LY7EfcY9GIRV2SRbB rRqqh7LAeqtETZrL8Azqxr/Jxyx/ceTzY/0knoY= X-Google-Smtp-Source: AK7set8dJ1c5fj/+InjLTRxGDtkgDmc4DQ/NZoLpAc1viElBzMC7XeNhlVA8p7PZDYHAKspYoL9EAkgsTHyu+340PJU= X-Received: by 2002:a50:bb65:0:b0:4ac:c720:207c with SMTP id y92-20020a50bb65000000b004acc720207cmr793530ede.5.1676642792245; Fri, 17 Feb 2023 06:06:32 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 17 Feb 2023 14:06:19 +0000 Message-ID: Subject: Re: Warning: shared mutable data To: Helmut Zeisel Cc: "gcc@gcc.gnu.org" Content-Type: multipart/alternative; boundary="0000000000000c106705f4e5d2fc" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000000c106705f4e5d2fc Content-Type: text/plain; charset="UTF-8" On Fri, 17 Feb 2023, 13:15 Helmut Zeisel via Gcc, wrote: > 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? > What exactly are you suggesting for the semantics of the warning? You haven't described what you want it to do, for anybody to say how difficult it would be. > 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 > > > --0000000000000c106705f4e5d2fc--