digitalmars.D - implicit enum conversions
- John C (20/20) Dec 20 2005 If the default underlying type of an enum member is int, why do I get th...
- Oskar Linde (4/29) Dec 20 2005 The DMD error message just displays two possible matches. There could be...
If the default underlying type of an enum member is int, why do I get the
error message below when the compiler tries to find a match for a function
overload?
enum Option { FIRST, SECOND }
test(bit value) {}
test(int value) {}
test(uint value) {}
test(float value) {}
test(double value) {}
int main() {
test(Option.FIRST);
return 0;
}
"function test called with argument types:
(Option)
matches both:
test(bit)
and:
test(double)"
Surely the best match would be 'test(int)'.
Dec 20 2005
John C wrote:
If the default underlying type of an enum member is int, why do I get the
error message below when the compiler tries to find a match for a function
overload?
enum Option { FIRST, SECOND }
test(bit value) {}
test(int value) {}
test(uint value) {}
test(float value) {}
test(double value) {}
int main() {
test(Option.FIRST);
return 0;
}
"function test called with argument types:
(Option)
matches both:
test(bit)
and:
test(double)"
Surely the best match would be 'test(int)'.
The DMD error message just displays two possible matches. There could be
more. See the front end source, func.c FuncDeclaration::overloadResolve()
/Oskar
Dec 20 2005
"Oskar Linde" <oskar.lindeREM OVEgmail.com> wrote in message news:do8ue1$1g5$1 digitaldaemon.com...John C wrote:So it seems that if there is more than one possible match, it's an error, as with numeric conversions. I've a suggestion: if the base type is specified on an enum (eg, enum Option : int), then that enum can only be implicitly converted to its base type, otherwise a cast is required and an error is reported.If the default underlying type of an enum member is int, why do I get the error message below when the compiler tries to find a match for a function overload? enum Option { FIRST, SECOND } test(bit value) {} test(int value) {} test(uint value) {} test(float value) {} test(double value) {} int main() { test(Option.FIRST); return 0; } "function test called with argument types: (Option) matches both: test(bit) and: test(double)" Surely the best match would be 'test(int)'.The DMD error message just displays two possible matches. There could be more. See the front end source, func.c FuncDeclaration::overloadResolve() /Oskar
Dec 20 2005
Oskar Linde wrote:John C wrote:[...]maybe the error should be: "function test called with argument types: (Option) has two or more matches: test(bit), test(double), ...""function test called with argument types: (Option) matches both: test(bit) and: test(double)" Surely the best match would be 'test(int)'.The DMD error message just displays two possible matches. There could be more. See the front end source, func.c FuncDeclaration::overloadResolve() /Oskar
Dec 20 2005









"John C" <johnch_atms hotmail.com> 