https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92338
Bug ID: 92338 Summary: double/float thought (ambiguous) candidate for C-array index. (Non numeric types aren't.) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mick.pearson at wildblue dot net Target Milestone: --- A double (float) conversion is considered candidate for indexing a C-array. A double (float) isn't allowed to access an array normally, so it's not good that this makes an int conversion operator "ambiguous". I tested this with some online GCC compilers... unfortunately none of them give the GCC version. I can't conveniently upgrade my GCC. {{{ #include <stdio.h> struct Test { operator int(){ return 0; } operator double(){ return 0; } }; int main() { printf("Hello World"); int test[2] = {}; int test2 = test[Test()]; return 0; } }}} {{{ Error(s): source_file.cpp: In function ‘int main()’: source_file.cpp:22:28: error: conversion from ‘Test’ to ‘long int’ is ambiguous int test2 = test[Test()]; ^ source_file.cpp:14:5: note: candidate: Test::operator double() operator double(){ return 0; } ^ source_file.cpp:13:5: note: candidate: Test::operator int() operator int(){ return 0; } ^ source_file.cpp:22:9: warning: unused variable ‘test2’ [-Wunused-variable] int test2 = test[Test()]; ^ }}}