Thread overview
alias syntax
Aug 02, 2009
Ellery Newcomer
Aug 02, 2009
Ellery Newcomer
Aug 02, 2009
Ellery Newcomer
Aug 05, 2009
Zarathustra
Aug 06, 2009
Ellery Newcomer
August 02, 2009
what is the purpose of the syntax

alias StorageClasses Declarator

?

(I just noticed my parser doesn't support it, but I don't see any reason to)
August 02, 2009
On Sat, Aug 1, 2009 at 8:31 PM, Ellery Newcomer<ellery-newcomer@utulsa.edu> wrote:
> what is the purpose of the syntax
>
> alias StorageClasses Declarator
>
> ?

I don't know where you're getting that grammar.  Is that from the D spec?
August 02, 2009
Jarrett Billingsley wrote:
> On Sat, Aug 1, 2009 at 8:31 PM, Ellery Newcomer<ellery-newcomer@utulsa.edu> wrote:
>> what is the purpose of the syntax
>>
>> alias StorageClasses Declarator
>>
>> ?
> 
> I don't know where you're getting that grammar.  Is that from the D spec?

um, yeah.

Declaration:
        typedef Decl
        alias Decl
        Decl

Decl:
        StorageClasses Decl
        BasicType Declarators ;
        BasicType Declarator FunctionBody
	AutoDeclaration


Never mind that's wrong.

but it looks like it should be

alias StorageClasses BasicType Declarator

plus some change. my mistake. emphasis on StorageClasses, not what comes after it.

Looking through declaration.c, I noticed that semantic disallows specifically

alias const {blah blah blah}

but not the others.

???!!!!!
August 02, 2009
On Sat, Aug 1, 2009 at 11:13 PM, Ellery Newcomer<ellery-newcomer@utulsa.edu> wrote:

> um, yeah.
>
> Declaration:
>        typedef Decl
>        alias Decl
>        Decl
>
> Decl:
>        StorageClasses Decl
>        BasicType Declarators ;
>        BasicType Declarator FunctionBody
>        AutoDeclaration
>
>
> Never mind that's wrong.
>
> but it looks like it should be
>
> alias StorageClasses BasicType Declarator

'Decl' is recursive.  So:

alias Decl

can expand to:

alias StorageClasses Decl

which expands to:

alias StorageClasses BasicType Declarators ;

But is this not what you're pointing out?  Are you instead taking issue with the fact that the grammar accepts something like "alias int foo() {}" whereas the compiler doesn't?

> Looking through declaration.c, I noticed that semantic disallows specifically
>
> alias const {blah blah blah}
>
> but not the others.

You mean how the compiler rejects "alias const int x;" but not "alias static int x;"?  That is strange..
August 02, 2009
> You mean how the compiler rejects "alias const int x;" but not "alias static int x;"?  That is strange..

I want to know why

alias static int x;

is allowed in the first place
August 05, 2009
Ellery Newcomer Wrote:

> > You mean how the compiler rejects "alias const int x;" but not "alias static int x;"?  That is strange..
> 
> I want to know why
> 
> alias static int x;
> 
> is allowed in the first place

d.grammar accepts: alias const int a; but compiler no (it is ok). d.grammar accepts: alias static int a; and compiler too

It is compiler fault or compiler just ignore this cases which seem haven't sense.

It is a grammar rule, in D there is much unnecessary (senseless ) notations.
For example:

void main(){
  alias static int a; // compiler will ignore alias
  final static int b; // compiler will ignore final
  alias final int b; // compiler will ignore alias and final
}
----------------------------------------------------------
class A{
  final int a; // final field doesn't have a sense
  scope int a; // A is still not-scope class
}
----------------------------------------------------------
module A;
private class AA{
}

module B;
import A;
void main(){
  AA aa = new AA; // class AA is not private
}
----------------------------------------------------------
As to your question:
class K{
  alias static int B;
  B b; // b is non-static
}
----------------------------------------------------------

August 06, 2009
> ----------------------------------------------------------
> As to your question:
> class K{
>   alias static int B;
>   B b; // b is non-static
> }
> ----------------------------------------------------------
> 

Curious. I didn't actually test the example, but I did for deprecated, and it doesn't get ignored.

Further investigation shows that scope also isn't ignored, but the rest are.

Also note that const is okay in a typedef, but not in an alias.

And going over into D2 land,

alias const(int) I; //is permitted, and
alias immutable int I; //is permitted, but
alias const int I; // bombs due to that one weird semantic rule

Oh well. I guess I'll just parse it and flag any use of it as an error.