Community
Participate
Working Groups
For the following code: #include <istream> class PipeIOS: public std::ios { public: }; class PipeInputStream: public PipeIOS, public std::istream { }; void foo() { PipeInputStream abc; if( abc.eof() != true ) { } } On the line with the if I get : 'eof' is ambiguous 'Candidates are: bool eof()' If it's ambiguous why only one candidates ;-) Cheers
I can't reproduce that with MinGW 4.4 but I can using the MS VC++ toolchain combined with VS 10 and Windows SDK 7.1. Are you using MS VC++ toolchain? Can you provide more information on your configuration?
It looks like this is the same case as this: class A { public: bool func(); }; class B: public A { }; class C: public A, B { }; void foo() { C c; c.func(); } This code and the original code provided do not compile, both compilers I mentioned consider the call ambiguous. So I guess this bug should be about improving the message since this is not a false positive.
(In reply to comment #2) > It looks like this is the same case as this: > class A > { > public: > bool func(); > }; > > class B: public A > { > }; > > class C: public A, B > { > }; > > void foo() > { > C c; > c.func(); > } > > This code and the original code provided do not compile, both compilers I > mentioned consider the call ambiguous. So I guess this bug should be about > improving the message since this is not a false positive. I'm using GCC 4.4.2 tool chain as provided by QNX. I didn't bother to compile this perticular code as it's a strip down version of a something larger, but I compiles just fine.
I also get the error on MacOSX 10.8 with the MacGCC toolchain: 'func' is ambiguous ' Candidates are: bool func()' It compiles fine for me with all C++ compilers I have (several versions of GCC and Clang). Marc-Andre, if you still get an error compiling that code, could you please post the output? I think it's pretty clear this is correct C++ code and CODAN gives a false positive. ----------- In a project of mine I have a similar error which I think is incorrect: 'toupper' is ambiguous ' Candidates are: std::basic_string<char,std::char_traits<char>,std::allocator<char>> toupper(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &) ' for this line of code: if (toupper(m_coordsys) == "GAL") { and the toupper function is defined like this: std::string toupper(const std::string& arg) { std::string s = arg; std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper); return s; } The function definition is in another referenced project and "Open Declaration" works fine. I was not able to reproduce this false positive error from CODAN in a small, isolated test case, but I can certainly try more if you think this is a different bug than the one discussed in this ticket and it would be useful. Note that another toupper function is defined in <cctype>, but I don't think that is the problem here: http://www.cplusplus.com/reference/clibrary/cctype/toupper/ In any case, giving an error that something is ambiguous with and a list of exactly one possibility seems to always be incorrect to me.
(In reply to comment #4) > I also get the error on MacOSX 10.8 with the MacGCC toolchain: > 'func' is ambiguous ' Candidates are: bool func()' > > It compiles fine for me with all C++ compilers I have (several versions of > GCC and Clang). > Marc-Andre, if you still get an error compiling that code, could you please > post the output? I think it's pretty clear this is correct C++ code and > CODAN gives a false positive. The code examples in comment #0 and comment #2 fail to compile with every version of GCC I tried (4.4-4.8) and with clang 3.3. So, I think it's appropriate for CDT to give an error as well. > In a project of mine I have a similar error which I think is incorrect: > 'toupper' is ambiguous ' Candidates are: > std::basic_string<char,std::char_traits<char>,std::allocator<char>> > toupper(const > std::basic_string<char,std::char_traits<char>,std::allocator<char>> &) ' > > for this line of code: > if (toupper(m_coordsys) == "GAL") { > > and the toupper function is defined like this: > > std::string toupper(const std::string& arg) > { > std::string s = arg; > std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper); > return s; > } > > The function definition is in another referenced project and "Open > Declaration" works fine. I was not able to reproduce this false positive > error from CODAN in a small, isolated test case, but I can certainly try > more if you think this is a different bug than the one discussed in this > ticket and it would be useful. > > Note that another toupper function is defined in <cctype>, but I don't think > that is the problem here: > http://www.cplusplus.com/reference/clibrary/cctype/toupper/ This seems like a different issue. If you still experience it, please file a new bug with a small test case. > In any case, giving an error that something is ambiguous with and a list of > exactly one possibility seems to always be incorrect to me. Agreed. Clang has a particularly nice way of presenting the error: test.cpp:18:7: error: non-static member 'func' found in multiple base-class subobjects of type 'A': class C -> class A class C -> class B -> class A c.func(); ^ test.cpp:4:10: note: member found by ambiguous name lookup bool func(); ^ I suggest we keep this bug open until CDT implements a nicer error message as well.
(In reply to comment #2) > It looks like this is the same case as this: > class A > { > public: > bool func(); > }; > > class B: public A > { > }; > > class C: public A, B > { > }; > > void foo() > { > C c; > c.func(); > } > > This code and the original code provided do not compile, both compilers I > mentioned consider the call ambiguous. So I guess this bug should be about > improving the message since this is not a false positive. Interestingly, CDT does not give an error for the following: test.hpp: template <typename> struct basic_A { bool eof() const; }; typedef basic_A<char> A; test.cpp: #include "test.hpp" class B : public A { }; class C : public A, public B { }; void foo() { C c; c.eof(); // no error here } This is actually a false *negative*. I filed bug 413406 for this.
(In reply to Nathan Ridge from comment #5) > Agreed. Clang has a particularly nice way of presenting the error: > > test.cpp:18:7: error: non-static member 'func' found in multiple base-class > subobjects of type 'A': > class C -> class A > class C -> class B -> class A > c.func(); > ^ > test.cpp:4:10: note: member found by ambiguous name lookup > bool func(); > ^ > > I suggest we keep this bug open until CDT implements a nicer error message > as well. I see Marc-Andre has filed bug 416315 for this. I think this report can be closed, then.
I think bug 416315 is a bit more "to the point" so we'll keep that one. *** This bug has been marked as a duplicate of bug 416315 ***