Bug 11632 – Old alias syntax accepts "ref"

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-28T07:29:22Z
Last change time
2024-12-13T18:14:30Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Dicebot
Moved to GitHub: dmd#18724 →

Comments

Comment #0 by public — 2013-11-28T07:29:22Z
When using old alias form, `ref` is both accepted and not making any effect: ----------- alias ref int RefInt; void foo(RefInt x) { x = 42; } void main() { int x; foo(x); import std.stdio : writeln; writeln(x); } ----------- 0 ----------- `alias RefInt = ref int` is rejected with "Error: basic type expected, not ref" so I assume it should be the same here.
Comment #1 by maxim — 2013-11-28T07:46:39Z
More nonsense: alias ref int ri; //alias in int ii; alias int oi; //alias lazy int li; //alias out int outi; alias pure int pi; alias @safe int si; //alias trusted int ti; alias nothrow int nthi; alias auto int ai; alias @property int pri; alias @disable int di; alias scope int sci; alias align(16) int ali; alias abstract int absi; alias final int fi; alias override int ovi; alias inout int inoui; alias synchronized int syi; alias static int stati; It is unclear however, whether this is a part of major accepts-invalid bug (dmd is permissive in allowing to apply attributes to declarations, so here is particular case) or defficiency in old alias syntax parsing.
Comment #2 by public — 2013-11-28T07:52:06Z
Whatever it is, current behavior is extremely confusing for newbies as one may expect it to actually work in example like provided in the first post.
Comment #3 by bearophile_hugs — 2013-11-28T08:02:54Z
See also Issue 3934
Comment #4 by andrej.mitrovich — 2014-04-22T21:17:36Z
*** Issue 12299 has been marked as a duplicate of this issue. ***
Comment #5 by andrej.mitrovich — 2014-04-22T21:17:49Z
*** Issue 12257 has been marked as a duplicate of this issue. ***
Comment #6 by rburners — 2015-06-04T02:30:13Z
phobos PR https://github.com/D-Programming-Language/phobos/pull/2995 is sort of blocked by: template RefType(T) alias RefType = ref T; not working anymore
Comment #7 by qs.il.paperinik — 2021-01-10T00:24:27Z
The grammar allows this to make alias RefDG = ref int delegate(); legal. Having ref be accepted but with no effect is nothing special about the D compiler. It accepts a lot of annotations that have no effect. The question which cases are accepts-invalid and which are not is mostly a matter of taste.
Comment #8 by robert.schadek — 2024-12-13T18:14:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18724 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB