digitalmars.D.learn - Cannot alias null
- Tom Browder via Digitalmars-d-learn (10/10) Jun 12 2014 This will not compile:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/11) Jun 12 2014 alias works only with types. Being an expression (not an object), null
- Andrew Edwards (4/19) Jun 12 2014 void foo() {}
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/13) Jun 12 2014 Seems to be an old behavior. That does not compile with 2.066:
- Adam D. Ruppe (3/3) Jun 12 2014 since null is a value maybe you want
- Tom Browder via Digitalmars-d-learn (5/8) Jun 12 2014 That works.
- monarch_dodra (26/29) Jun 12 2014 I *think* the issue might be that "null" is an rvalue? Because
This will not compile: alias blah = null; The dmd message are: di/test_hdr.d(10): Error: basic type expected, not null di/test_hdr.d(10): Error: semicolon expected to close alias declaration di/test_hdr.d(10): Error: Declaration expected, not 'null' Are there any other objects that cannot be aliased? Thanks, Best, -Tom
Jun 12 2014
On 06/12/2014 01:26 PM, Tom Browder via Digitalmars-d-learn wrote:This will not compile: alias blah = null; The dmd message are: di/test_hdr.d(10): Error: basic type expected, not null di/test_hdr.d(10): Error: semicolon expected to close alias declaration di/test_hdr.d(10): Error: Declaration expected, not 'null' Are there any other objects that cannot be aliased?alias works only with types. Being an expression (not an object), null cannot not work with alias. Ali
Jun 12 2014
On 6/12/14, 4:29 PM, Ali Çehreli wrote:On 06/12/2014 01:26 PM, Tom Browder via Digitalmars-d-learn wrote: > This will not compile: > > alias blah = null; > > The dmd message are: > > di/test_hdr.d(10): Error: basic type expected, not null > di/test_hdr.d(10): Error: semicolon expected to close alias declaration > di/test_hdr.d(10): Error: Declaration expected, not 'null' > > Are there any other objects that cannot be aliased? alias works only with types. Being an expression (not an object), null cannot not work with alias. Alivoid foo() {} alias bar = foo(); Am I just misunderstanding what is meant by types?
Jun 12 2014
On 06/12/2014 01:36 PM, Andrew Edwards wrote:void foo() {} alias bar = foo(); Am I just misunderstanding what is meant by types?Seems to be an old behavior. That does not compile with 2.066: Error: function declaration without return type. (Note that constructors are always named 'this') The following compiles though: alias bar = foo; I stand corrected: alias works not only with types but with symbols as well. I was right about the original code though: "Aliases cannot be used for expressions". Ali
Jun 12 2014
since null is a value maybe you want enum blah = null; you may also give it a type after the enum word
Jun 12 2014
On Thu, Jun 12, 2014 at 4:58 PM, Adam D. Ruppe via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:since null is a value maybe you want enum blah = null;That works.you may also give it a type after the enum wordBut I can't get any other variant to work so far. -Tom
Jun 12 2014
On Thursday, 12 June 2014 at 21:58:32 UTC, Adam D. Ruppe wrote:since null is a value maybe you want enum blah = null; you may also give it a type after the enum wordI *think* the issue might be that "null" is an rvalue? Because you can alias variable names all you want. I do it all the time for templates where I *may* need a temporary. eg: void foo(T)(T val) { static if (isUnsigned!T) alias uval = val; else auto uval = unsigned(val); ... } It's also quite useful with varargs: alias a0 = args[0]; Also, you can't alias things like "int.init" either. I'm not sure the "rvalue" thing is the source, because these work: //----struct S { static int i; static int j() property; } alias a = S.i; alias b = S.j; //---- I'd consider filling a bug report.
Jun 12 2014