D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11632 - Old alias syntax accepts "ref"
Summary: Old alias syntax accepts "ref"
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
: 12257 12299 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-11-28 07:29 UTC by Dicebot
Modified: 2024-12-13 18:14 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dicebot 2013-11-28 07:29:22 UTC
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 Maxim Fomin 2013-11-28 07:46:39 UTC
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 Dicebot 2013-11-28 07:52:06 UTC
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 bearophile_hugs 2013-11-28 08:02:54 UTC
See also Issue 3934
Comment 4 Andrej Mitrovic 2014-04-22 21:17:36 UTC
*** Issue 12299 has been marked as a duplicate of this issue. ***
Comment 5 Andrej Mitrovic 2014-04-22 21:17:49 UTC
*** Issue 12257 has been marked as a duplicate of this issue. ***
Comment 6 Robert Schadek 2015-06-04 02:30:13 UTC
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 Bolpat 2021-01-10 00:24:27 UTC
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 dlangBugzillaToGithub 2024-12-13 18:14:30 UTC
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