Thread overview
[Issue 13309] DMD accepts yet another invalid alias declaration
Aug 17, 2014
Orvid King
Aug 17, 2014
Orvid King
Aug 19, 2014
Andrej Mitrovic
Aug 19, 2014
Kenji Hara
Dec 17, 2022
Iain Buclaw
August 17, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

briancschott@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
             Blocks|                            |10233

--
August 17, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

Orvid King <blah38621@gmail.com> changed:

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

--- Comment #1 from Orvid King <blah38621@gmail.com> ---
Your suggested alternative wouldn't do the same as that declaration currently does, because it would be typed as a pointer to a function rather than a function type itself, which is what the mangled type of the alias is.

--
August 17, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

--- Comment #2 from Orvid King <blah38621@gmail.com> ---
To be more precise, the alias declaration, as output in the JSON is:
"name" : "fnNtQuerySystemInformation",
"deco" : "WNbkPvkPkZi"

--
August 19, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--- Comment #3 from hsteoh@quickfur.ath.cx ---
This looks like the old alias syntax `alias originalSymbol newSymbol;`. For functions, it appears to be following C/C++'s totally counterintuitive pattern of function pointer declaration `returnType (*ptrName)(... /*arguments*/)`. In this case, it appears to be aliasing a function that takes (uint, void*, uint, uint*) arguments and returns HRESULT to the name fnNtQuerySystemInformation.

--
August 19, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com

--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
Note that alias "symbol = extern(spec)" is currently broken and won't set the
right specifier (or was that just in the parameter lists? I'm not sure).

--
August 19, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to briancschott from comment #0)
> alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint
> SystemInformationClass, void* info, uint infoLength, uint* ReturnLength )
> nothrow;
> 
> This does not match any documented form of alias declaration, yet it is accepted by DMD.

> alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint SystemInformationClass, void* info, uint infoLength, uint* ReturnLength ) nothrow;

No, it's valid in the grammar.

AliasDeclaration:
    alias StorageClasses_opt BasicType Declarator

Declarator:
    BasicType2_opt Identifier DeclaratorSuffixes_opt

DeclaratorSuffix:
    Parameters MemberFunctionAttributes_opt

Parameters:
    ( ParameterList_opt )

...

And then, the name fnNtQuerySystemInformation will alias a function type:

extern(Windows) HRESULT(uint, void*, uint, uint*) nothrow

--
August 19, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

--- Comment #6 from briancschott@gmail.com ---
So in other words this is allowed because we're still allowing C-style declarations such as "int a[]".

--
August 19, 2014
https://issues.dlang.org/show_bug.cgi?id=13309

--- Comment #7 from briancschott@gmail.com ---
alias int a(int), b(int);

test.d(1): Error: multiple declarations must have the same type, not int(int)
and int(int)

It's the same stupid thing again!

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=13309

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
October 19
https://issues.dlang.org/show_bug.cgi?id=13309

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |nick@geany.org
         Resolution|---                         |INVALID

--- Comment #8 from Nick Treleaven <nick@geany.org> ---
(In reply to Kenji Hara from comment #5)
> No, it's valid in the grammar.
...
> And then, the name fnNtQuerySystemInformation will alias a function type:
> 
> extern(Windows) HRESULT(uint, void*, uint, uint*) nothrow

So this was invalid. Also the new alias syntax allows aliasing a function type:

// old
alias extern(Windows) HRESULT fnNtQuerySystemInformation( uint
SystemInformationClass, void* info, uint infoLength, uint* ReturnLength )
nothrow;
// new
alias fnNtQuerySystemInformation = extern(Windows) HRESULT(uint
SystemInformationClass, void* info, uint infoLength, uint* ReturnLength)
nothrow;

--