digitalmars.D.bugs - alias bug (dmd .121)
- zwang <nehzgnaw gmail.com> May 01 2005
- Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> May 03 2005
- "Walter" <newshound digitalmars.com> May 07 2005
- =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= May 07 2005
- "Walter" <newshound digitalmars.com> May 08 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 01 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 03 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 07 2005
-----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:
# 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
iD8DBQFCfa1z3w+/yD4P9tIRAl0FAJ45ldjTNUfHyaLnHnbsUa1/TewiiACgh3P/
UiIxpykuYWwb45FrOJG+DMo=
=RyAT
-----END PGP SIGNATURE-----
May 07 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 08 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-----
May 11 2005









Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> 