can gcc warn about this ambiguous function call in a '?:'?

Matthew Woehlke mw_triad@users.sourceforge.net
Fri Sep 14 16:01:00 GMT 2007


$ gcc --version
gcc (GCC) 4.1.2

I have a program that looks roughly like this:

class Bar {
   Bar(int);
   Bar(char*);
   // details aren't important
}

foo(Bar b) {
   // ...
}

foo(bool a) {
   foo (a ? 0 : Bar("hello"));
}

Basically, two overloads where one takes a bool and calls the other, 
which has an identical signature except s/bool/Bar/, where one can pass 
'0' for a Bar. As a result, the call when a==true is ambiguous... but 
g++ -Wall doesn't warn about this. I was also a bit surprised that gcc 
is generating code that calls a different function depending on the ?: 
expression (maybe I shouldn't be), but it seems unlikely that this sort 
of thing would be done intentionally very often.

So... is there a warning for this? Can/should there be?

(If anyone really, really wants to know, I found this in [1], revision 
712217 and fixed it in 712488. See the diff at [2].)

1: 
svn://anonsvn/kde/org/home/kde.trunk/KDE/kdebase/runtime/kstyles/oxygen/oxygen.cpp

2: 
http://websvn.kde.org/trunk/KDE/kdebase/runtime/kstyles/oxygen/oxygen.cpp?r1=712217&r2=712488

-- 
Matthew
The prhase "less is more" takes on a whole new meaning if you think 
about standard Unix tools.



More information about the Gcc-help mailing list