Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 20, 2005 implicit enum conversions | ||||
---|---|---|---|---|
| ||||
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)'. |
December 20, 2005 Re: implicit enum conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | 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 |
December 20, 2005 Re: implicit enum conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Oskar Linde | "Oskar Linde" <oskar.lindeREM@OVEgmail.com> wrote in message news:do8ue1$1g5$1@digitaldaemon.com... > 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 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. |
December 20, 2005 Re: implicit enum conversions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Oskar Linde | Oskar Linde wrote: > John C wrote: > [...] >> >> "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 maybe the error should be: "function test called with argument types: (Option) has two or more matches: test(bit), test(double), ..." |
Copyright © 1999-2021 by the D Language Foundation