У меня очень простой код:
typedef long int32;
typedef unsigned long uint32;
enum Foo : int32 {
kE1 = 100
};
bool f(int32 i) {
return true;
}
bool f(uint32 i) {
return false;
}
int main()
{
int32 i32 = 8;
uint32 ui32 = 10;
f(i32);
f(ui32);
f(Foo::kE1);
return 0;
}
При компиляции с помощью инструментов Visual Studio Build 2017 я получаю сообщение об ошибке:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /Zi /nologo /W3 /WX- /diagnostics:classic /Od /Ob0 /Oy- /D WIN32
/D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Fo"cpp17.dir\Debug\\" /Fd"cpp17.dir\Deb
ug\vc141.pdb" /Gd /TP /analyze- /FC /errorReport:queue D:\Work\test\cpp17\main.cpp
main.cpp
d:\work\test\cpp17\main.cpp(24): error C2668: 'f': ambiguous call to overloaded function [D:\Work\test\cpp17\build\cpp17.vcxproj]
d:\work\test\cpp17\main.cpp(12): note: could be 'bool f(uint32)'
d:\work\test\cpp17\main.cpp(8): note: or 'bool f(int32)'
d:\work\test\cpp17\main.cpp(24): note: while trying to match the argument list '(Foo)'
Done Building Project "D:\Work\test\cpp17\build\cpp17.vcxproj" (default targets) -- FAILED.
Я не понимаю, что этоэто неоднозначный вызов. Перечисление четко помечено как имеющее тип int32
(enum Foo : int32
).
У меня нет этой проблемы на macOS с XCode.
Я что-то не так делаю? Это проблема с инструментами сборки Visual Studio?