https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96761
Bug ID: 96761 Summary: "error: call of overloaded ‘func(size_t)’ is ambiguous" when argument is size_t(0) and func(int) and func(const char *) are visible Product: gcc Version: 9.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: darktemplar at basealt dot ru Target Milestone: --- Following example fails to compile with g++-9.3.1: #include <stdio.h> #include <stddef.h> void func(int arg) { printf("Called func(int) with arg = %d\n", arg); } void func(const char *arg) { printf("Called func(const char*) with arg = \"%s\"\n", arg); } int main(int argc, char **argv) { func(size_t(0)); func(0); func(size_t(1)); func(size_t(1) - size_t(1)); #define emptystring "" #define nonemptystring "non empty string" func(emptystring); func(sizeof(emptystring) - 1); func(nonemptystring); func(sizeof(nonemptystring) - 1); return 0; } It fails to compile on line "func(size_t(0));" but lines "func(0);", "func(size_t(1));", "func(size_t(1) - size_t(1));" and "func(sizeof(emptystring) - 1);" are compiled fine. This result looks inconsistent. Compilation result is: $ g++ test.cpp -o test test.cpp: In function ‘int main(int, char**)’: test.cpp:16:16: error: call of overloaded ‘func(size_t)’ is ambiguous 16 | func(size_t(0)); | ^ test.cpp:4:6: note: candidate: ‘void func(int)’ 4 | void func(int arg) | ^~~~ test.cpp:9:6: note: candidate: ‘void func(const char*)’ 9 | void func(const char *arg) | ^~~~ Expected result: Successful compilation, with "func(int)" being chosen for "func(size_t(0))" call. g++ version: $ LC_ALL=C g++ --version x86_64-alt-linux-g++ (GCC) 9.3.1 20200518 (ALT Sisyphus 9.3.1-alt1) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.