Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 355767 - [fp] 'eof' is ambiguous
Summary: [fp] 'eof' is ambiguous
Status: CLOSED DUPLICATE of bug 416315
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: CDT Codan Inbox CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-24 17:09 EDT by Mario Charest CLA
Modified: 2013-09-02 22:58 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Charest CLA 2011-08-24 17:09:28 EDT
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
Comment 1 Marc-André Laperle CLA 2011-08-26 18:06:11 EDT
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?
Comment 2 Marc-André Laperle CLA 2011-08-26 18:22:24 EDT
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.
Comment 3 Mario Charest CLA 2011-08-27 23:46:54 EDT
(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.
Comment 4 Christoph Deil CLA 2012-09-16 13:10:25 EDT
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.
Comment 5 Nathan Ridge CLA 2013-07-21 19:33:23 EDT
(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.
Comment 6 Nathan Ridge CLA 2013-07-21 19:43:40 EDT
(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.
Comment 7 Nathan Ridge CLA 2013-09-02 19:54:30 EDT
(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.
Comment 8 Marc-André Laperle CLA 2013-09-02 22:58:03 EDT
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 ***