www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - alias bug (dmd .121)

reply zwang <nehzgnaw gmail.com> writes:
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 01 2005
next sibling parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----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 03 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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 07 2005
parent reply =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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:


is the same as


But

isn't the same as


Is this correct?

Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCfa1z3w+/yD4P9tIRAl0FAJ45ldjTNUfHyaLnHnbsUa1/TewiiACgh3P/
UiIxpykuYWwb45FrOJG+DMo=
=RyAT
-----END PGP SIGNATURE-----
May 07 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"Thomas Kühne" <thomas-dloop kuehne.THISISSPAM.cn> wrote in message
news:d5kaml$ng6$1 digitaldaemon.com...
 Just to make sure:


 is the same as

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

 isn't the same as


 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 08 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----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:


 is the same as

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

 isn't the same as


 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: legal: As a consequence would be illegal too. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCgkc63w+/yD4P9tIRAmWOAJ0R93t1mpK01WEW2vYkQj/VRGGjdgCeORFE +lHhata1dRZM9xqdymUQIcI= =TgXC -----END PGP SIGNATURE-----
May 11 2005