Thread overview
alias bug (dmd .121)
May 01, 2005
zwang
May 03, 2005
Thomas Kuehne
May 08, 2005
Walter
May 08, 2005
Thomas Kühne
May 08, 2005
Walter
May 11, 2005
Thomas Kuehne
May 01, 2005
I'm not sure if this bug was reported before:

<code>
void main(char[][] args){
	alias const char[] CS;
	CS cs = "string";
	switch(args[0]){
	case cs: break;
	}
}
</code>

The code above is equivalent to

<code>
void main(char[][] args){
	const char[] cs = "string";
	switch(args[0]){
	case cs: break;
	}
}
</code>

and should also compile, but dmd reports:
"test.d(4): case must be a string or an integral constant, not cs"
May 03, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zwang schrieb am Sun, 01 May 2005 16:32:06 +0800:
> I'm not sure if this bug was reported before:
>
><code>
> void main(char[][] args){
> 	alias const char[] CS;
> 	CS cs = "string";
> 	switch(args[0]){
> 	case cs: break;
> 	}
> }
></code>
>
> The code above is equivalent to
>
><code>
> void main(char[][] args){
> 	const char[] cs = "string";
> 	switch(args[0]){
> 	case cs: break;
> 	}
> }
></code>
>
> and should also compile, but dmd reports:
> "test.d(4): case must be a string or an integral constant, not cs"

Added to DStress as http://dstress.kuehne.cn/run/switch_22.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFCd8yX3w+/yD4P9tIRAttIAKCODLmez5SYbSNmUeLqB9jQ6sQP1gCfRCua
QJr8jy9rGed3mS74qpmZHqk=
=Ehaw
-----END PGP SIGNATURE-----
May 08, 2005
"zwang" <nehzgnaw@gmail.com> wrote in message news:d5247u$28ch$2@digitaldaemon.com...
> I'm not sure if this bug was reported before:
>
> <code>
> void main(char[][] args){
> alias const char[] CS;
> CS cs = "string";
> switch(args[0]){
> case cs: break;
> }
> }
> </code>
[...]
> and should also compile, but dmd reports:
> "test.d(4): case must be a string or an integral constant, not cs"

What's happening here is const is not part of the type (like it is in C++) but a storage class. Aliases are for types or symbols, not storage classes. Hence, the 'const' is not part of the alias. The example works if the declaration is:

    const CS cs = "string";

Not a compiler bug.


May 08, 2005
Walter wrote:
| "zwang" <nehzgnaw@gmail.com> wrote in message
| news:d5247u$28ch$2@digitaldaemon.com...
|
|>I'm not sure if this bug was reported before:
|>
|><code>
|>void main(char[][] args){
|>alias const char[] CS;
|>CS cs = "string";
|>switch(args[0]){
|>case cs: break;
|>}
|>}
|></code>
|
| [...]
|
|>and should also compile, but dmd reports:
|>"test.d(4): case must be a string or an integral constant, not cs"
|
|
| What's happening here is const is not part of the type (like it is in
| C++) but a storage class. Aliases are for types or symbols, not
| storage classes.
| Hence, the 'const' is not part of the alias. The example works if the
| declaration is:
|
|     const CS cs = "string";
|
| Not a compiler bug.

http://digitalmars.com/d/declaration.html
| Declaration:
|		alias Decl
| Decl:
|		StorageClass Decl

Just to make sure:

# alias const type mType;
is the same as
# alias type mType;

But
# alias public some.imported.privateSymbol x;
isn't the same as
# alias some.imported.privateSymbol x;

Is this correct?

Thomas
May 08, 2005
"Thomas Kühne" <thomas-dloop@kuehne.THISISSPAM.cn> wrote in message news:d5kaml$ng6$1@digitaldaemon.com...
> Just to make sure:
>
> # alias const type mType;
> is the same as
> # alias type mType;

Yes. The 'const' is just ignored because it has no meaning when applied to alias. One could argue this should result in an error message.

> But
> # alias public some.imported.privateSymbol x;
> isn't the same as
> # alias some.imported.privateSymbol x;
>
> Is this correct?

Yes. Here the 'public' applies to the accessibility of x itself, and has nothing to do with what x is an alias of.


May 11, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Walter schrieb am Sun, 8 May 2005 02:17:34 -0700:
>
> "Thomas Kühne" <thomas-dloop@kuehne.THISISSPAM.cn> wrote in message news:d5kaml$ng6$1@digitaldaemon.com...
>> Just to make sure:
>>
>> # alias const type mType;
>> is the same as
>> # alias type mType;
>
> Yes. The 'const' is just ignored because it has no meaning when applied to alias. One could argue this should result in an error message.
>
>> But
>> # alias public some.imported.privateSymbol x;
>> isn't the same as
>> # alias some.imported.privateSymbol x;
>>
>> Is this correct?
>
> Yes. Here the 'public' applies to the accessibility of x itself, and has nothing to do with what x is an alias of.

How about cleaning up the alias syntax?

illegal:
#
# <static|final|abstract|const|auto|override> alias Declarator Declarator
#

legal:
#
# <deprecated|private|package|protected|public|export> alias
# Declarator Declarator
#

As a consequence
#
# alias <any attribute> Declarator Declarator
#
would be illegal too.

Thomas



-----BEGIN PGP SIGNATURE-----

iD8DBQFCgkc63w+/yD4P9tIRAmWOAJ0R93t1mpK01WEW2vYkQj/VRGGjdgCeORFE
+lHhata1dRZM9xqdymUQIcI=
=TgXC
-----END PGP SIGNATURE-----