Bug 3669 – Default parameter initialization of size_t can result in errors about implicit conversions to uint
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2010-01-03T20:28:00Z
Last change time
2015-06-09T01:27:14Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2010-01-03T20:28:01Z
Okay. Basically, under some circumstances, a default initialization for a function parameter of type size_t with an argument of type size_t results in a complaint about uint not being convertible to size_t. For instance, given the following code:
size_t getNum(size_t num = DEF_NUM)
{
return num;
}
void main()
{
size_t num = getNum();
}
size_t DEF_NUM = 10;
you get the error
temp.d(5): Error: cannot implicitly convert expression (DEF_NUM) of type size_t to uint
However, if you put the declaration of DEF_NUM first:
size_t DEF_NUM = 10;
size_t getNum(size_t num = DEF_NUM)
{
return num;
}
void main()
{
size_t num = getNum();
}
it will compile. So, it appears to have something to do with the declaration order. If you were to replace getNum() with DEF_NUM, that is
void main()
{
size_t num = DEF_NUM;
}
size_t DEF_NUM = 10;
then it compiles. It doesn't matter whether DEF_NUM or main is declared first, it compiles either way. So, it appears to have something to do with default initialization of a function parameter. In any case, all of the variables involved are size_t, so there shouldn't be any complaints about conversions. I assume that size_t is actually uint and that there's some kind of aliasing issue, but I don't know.
The compiler version that I'm using is actually 2.0.39, not 2.0.38, but 2.0.39 wasn't in the list - too new I guess. Also, my machine is x86_64, so I put x86_64 for the hardware, but since dmd is only 32 bit, I doubt that it matters. But that's my hardware, so that's what I put.
Comment #1 by braddr — 2011-02-06T15:40:06Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.