public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "alex at sunopti dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug d/97843] Bad code gen when concatenating to array
Date: Mon, 16 Nov 2020 20:56:54 +0000	[thread overview]
Message-ID: <bug-97843-4-DDNgrPiI5i@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97843-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #6 from Alex <alex at sunopti dot com> ---
>From cppreference.com :

The behavior of every builtin compound-assignment expression E1 op= E2 (where
E1 is a modifiable lvalue expression and E2 is an rvalue expression or a
braced-init-list (since C++11)) is exactly the same as the behavior of the
expression E1 = E1 op E2.

I think the D spec should contain something similar. It's omission is an
oversight. I don't think D developers intend different expression evaluation
behavior to C++.

If the above were part of the D spec, the equivalent code would be :

bytes = bytes ~ bytes.sum

The assignment must happen after the ~.

In the same way that the ~= must happen after the sum in bytes ~= bytes.sum

Maybe I should raise an issue with the D spec ?
Either way I don't think the compiler should do this because it doesn't make
sense. This is the first compiler release where my unit tests have detected
this behaviour.

>ref ubyte[] extend(ref ubyte[] bytes)
>{
>    bytes.length += 1;
>    bytes[$-1] = 0xde;
>    return bytes;
>}

>extend(bytes)[bytes.length] = bytes.sum;

This would be ok if a trailing ~ meant 'extend the array and return the last
element'. Then it could be evaluated before the assignment.

The assignment operator ~= should be considered to be both the ~ and the =
grouped together.

  parent reply	other threads:[~2020-11-16 20:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16  1:11 [Bug d/97843] New: " alex at sunopti dot com
2020-11-16 11:31 ` [Bug d/97843] " ibuclaw at gdcproject dot org
2020-11-16 12:16 ` alex at sunopti dot com
2020-11-16 15:34 ` ibuclaw at gdcproject dot org
2020-11-16 15:35 ` ibuclaw at gdcproject dot org
2020-11-16 16:17 ` ibuclaw at gdcproject dot org
2020-11-16 20:56 ` alex at sunopti dot com [this message]
2020-11-18 10:32 ` cvs-commit at gcc dot gnu.org
2020-11-18 10:37 ` ibuclaw at gdcproject dot org
2020-11-18 10:38 ` ibuclaw at gdcproject dot 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-97843-4-DDNgrPiI5i@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).