Jump to page: 1 2
Thread overview
[Issue 12885] const union wrongly converts implicitly to mutable
Jun 24, 2014
Nils
Sep 21, 2018
FeepingCreature
Nov 01, 2018
Martin Nowak
Dec 16, 2018
Walter Bright
Dec 16, 2018
Walter Bright
Dec 16, 2018
Walter Bright
May 19, 2022
Ate Eskola
Dec 17, 2022
Iain Buclaw
Jun 17
Dlang Bot
Jun 20
Dlang Bot
June 16, 2014
https://issues.dlang.org/show_bug.cgi?id=12885
Issue 12885 depends on issue 12883, which changed state.

Issue 12883 Summary: implicit conversion of struct to mutable via alias this https://issues.dlang.org/show_bug.cgi?id=12883

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |INVALID

--
June 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12885

Nils <nilsbossung@googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|nilsbossung@googlemail.com  |nobody@puremagic.com

--- Comment #1 from Nils <nilsbossung@googlemail.com> ---
As issue 12883 has been closed as invalid, I don't have a plan how to go about this. Unassigning from me.

--
September 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12885

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com

--
September 21, 2018
https://issues.dlang.org/show_bug.cgi?id=12885

FeepingCreature <default_357-line@yahoo.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |default_357-line@yahoo.de
           Severity|enhancement                 |normal

--- Comment #2 from FeepingCreature <default_357-line@yahoo.de> ---
I just ran into this. This bug breaks std.json quite badly: see https://issues.dlang.org/show_bug.cgi?id=19256 , in which const(JSONValue) implicitly converts to JSONValue, allowing us to mutate JSON objects via a const parameter.

This is definitely unacceptable.

--
November 01, 2018
https://issues.dlang.org/show_bug.cgi?id=12885

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu

--- Comment #3 from Martin Nowak <code@dawg.eu> ---
I don't fully agree with the reasoning in issue 11257.
It seems like casts could be used to bypass const checks for implementations of
Rebindable et.al.

--
November 15, 2018
https://issues.dlang.org/show_bug.cgi?id=12885
Issue 12885 depends on issue 12883, which changed state.

Issue 12883 Summary: implicit conversion of struct to mutable via alias this https://issues.dlang.org/show_bug.cgi?id=12883

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--
December 16, 2018
https://issues.dlang.org/show_bug.cgi?id=12885

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
Martin is right.

--
December 16, 2018
https://issues.dlang.org/show_bug.cgi?id=12885

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
https://github.com/dlang/dmd/pull/9061

--
December 16, 2018
https://issues.dlang.org/show_bug.cgi?id=12885

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=12883,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=19256,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=11257

--
May 15, 2022
https://issues.dlang.org/show_bug.cgi?id=12885

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #6 from Steven Schveighoffer <schveiguy@gmail.com> ---
I just ran into this, with vibe.d Json type. Well, not a problem exactly, I just noticed I happened to be stripping const by accident, and it alarmed me that the compiler lets you get away with it.

I will note that this fails:

```d
union U
{
   int *p;
   int i;
}
void main()
{
   const U c;
   U m = c;
}
```

I see no reason why this should fail but the other should not, the inconsistency itself is a problem.

But beyond that, I will note that a struct that contains such an overlapping is convertible from const to mutable in @safe code. This in itself isn't a problem since you can't access the pointer value in @safe code. But surely if you wanted to provide access for @safe callers (like, for a tagged union, like Json), there would be trusted escapes, and those would surely not expect an implicit conversion of a const pointer to a mutable pointer.

--
« First   ‹ Prev
1 2