www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Alias / typedef bug with bool

reply Roberto Mariottini <Roberto_member pathlink.com> writes:
In the following sample:

----
import std.stdio;
 
bool t = true;
bool f = false;
 
void print(bool b)
{
  writefln("#B: ", b);
}
 
void print(bit b)
{
  writefln("#T: ", b);
}
 
int main()
{
  print(t);
  print(f);
  print(true);
  print(false);
}
----

compiling with DMD v0.139 on Windows XP I get:

testBool.d(18): function testBool.print called with argument types:
(bit)
matches both:
testBool.print(bit)
and:
testBool.print(bit)
testBool.d(19): function testBool.print called with argument types:
(bit)
matches both:
testBool.print(bit)
and:
testBool.print(bit)
testBool.d(20): function testBool.print called with argument types:
(bit)
matches both:
testBool.print(bit)
and:
testBool.print(bit)
testBool.d(21): function testBool.print called with argument types:
(bit)
matches both:
testBool.print(bit)
and:
testBool.print(bit)

I don't understand:

- If bool is an alias for bit, then the declaration of the two functions shoul
have failed at line 11.
- If bool is a typedef for bit, then the program should have compiled correctly.

Ciao
Nov 08 2005
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roberto Mariottini schrieb am 2005-11-08:
 In the following sample:

 ----
 import std.stdio;
  
 bool t = true;
 bool f = false;
  
 void print(bool b)
 {
   writefln("#B: ", b);
 }
  
 void print(bit b)
 {
   writefln("#T: ", b);
 }
  
 int main()
 {
   print(t);
   print(f);
   print(true);
   print(false);
 }
 ----

 compiling with DMD v0.139 on Windows XP I get:

 testBool.d(18): function testBool.print called with argument types:
 (bit)
 matches both:
 testBool.print(bit)
 and:
 testBool.print(bit)
 testBool.d(19): function testBool.print called with argument types:
 (bit)
 matches both:
 testBool.print(bit)
 and:
 testBool.print(bit)
 testBool.d(20): function testBool.print called with argument types:
 (bit)
 matches both:
 testBool.print(bit)
 and:
 testBool.print(bit)
 testBool.d(21): function testBool.print called with argument types:
 (bit)
 matches both:
 testBool.print(bit)
 and:
 testBool.print(bit)

 I don't understand:

 - If bool is an alias for bit, then the declaration of the two functions shoul
 have failed at line 11.
 - If bool is a typedef for bit, then the program should have compiled
correctly.

Bool is an alias for bit (-> dmd/src/phobos/object.d:6). http://dstress.kuehne.cn/nocompile/alias_05.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDdkBE3w+/yD4P9tIRAs8FAJ9pAALroEpNdDJA9cCFpFolE7j2ZACgz/RX 5+l1p5DLAebt1W+qeooarUU= =i+pU -----END PGP SIGNATURE-----
Nov 12 2005