public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14790] New: C++: ambigous overload compile failure - new case different from 1675
@ 2004-03-30 23:45 osf at squirrely dot net
  2004-03-30 23:53 ` [Bug c++/14790] " bangerth at dealii dot org
  2004-03-31 10:49 ` reichelt at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: osf at squirrely dot net @ 2004-03-30 23:45 UTC (permalink / raw)
  To: gcc-bugs

/*
 * gpp overloading bug report
 *
 * frank m spies        osf@squirrely.net
 *
 *
 * this was tested with g++ 2.96 on an sun ultra sparc and 3.3.1 (cygwin) on
 * an amd athlon running win2k sp4
 * no options used .. just straight
 * g++ gpp_bug.cpp
 *
 * the compile error without the functions in final_derived are:

gpp_bug.cpp: In function `int main()':
gpp_bug.cpp:79: error: request for member `connect_to' is ambiguous
gpp_bug.cpp:39: error: candidates are: virtual void base2::connect_to(base2*)
gpp_bug.cpp:31: error:                 virtual void base1::connect_to(base1*)

 * with the functions in final_derived it compiles just fine
 *
 * this is a bug to me because even though the two base classes have the same
 * member function name the parameters given are of completely different type
 * not even sharing a base class. though even if they share a base class it
 * should still choose the right one.
 */

class   base1
{
public:
virtual void    connect_to(base1*)
{
}
};

class   base2
{
public:
virtual void    connect_to(base2*)
{
}
};

class   derived1 : public base1
{
public:
};

class   derived2 : public base2
{
public:
};

class   final_derived : public derived1, public derived2
{
public:
/**
 * comment these 2 functions out to get a compile error
 *
virtual void    connect_to(base1*)
{
}
virtual void    connect_to(base2*)
{
}
**
 * comment out from up there to down here to get the compile error
 *
 * if you leave those 2 functions in it compiles fine (workaround but painful)
 * if you take them out it does not compile
 *
 * tested under g++ 2.96 and 3.3.1 (cygwin)
 */
};


main()
{
        final_derived fd;
        fd.connect_to(new derived1());
}

-- 
           Summary: C++: ambigous overload compile failure - new case
                    different from 1675
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: osf at squirrely dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14790


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/14790] C++: ambigous overload compile failure - new case different from 1675
  2004-03-30 23:45 [Bug c++/14790] New: C++: ambigous overload compile failure - new case different from 1675 osf at squirrely dot net
@ 2004-03-30 23:53 ` bangerth at dealii dot org
  2004-03-31 10:49 ` reichelt at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: bangerth at dealii dot org @ 2004-03-30 23:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-03-30 23:53 -------
With this stripped down (equivalent) program 
------------------ 
struct   base1 { void foo(base1*); }; 
struct   base2 { void foo(base2*); }; 
 
struct   derived : public base1, public base2 {}; 
 
int main() { 
  derived fd; 
  fd.foo(new base1()); 
} 
------------------- 
I get errors with both gcc and icc: 
g/x> c++ -c x.cc 
x.cc: In function `int main()': 
x.cc:8: error: request for member `foo' is ambiguous 
x.cc:2: error: candidates are: void base2::foo(base2*) 
x.cc:1: error:                 void base1::foo(base1*) 
g/x> icc -c -Xc -ansi x.cc 
x.cc(8): error: "derived::foo" is ambiguous 
    fd.foo(new base1()); 
       ^ 
 
compilation aborted for x.cc (code 2) 
 
I am pretty sure the code is invalid, but someone may be able to cite 
the relevant paragraphs. 
 
W. 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14790


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/14790] C++: ambigous overload compile failure - new case different from 1675
  2004-03-30 23:45 [Bug c++/14790] New: C++: ambigous overload compile failure - new case different from 1675 osf at squirrely dot net
  2004-03-30 23:53 ` [Bug c++/14790] " bangerth at dealii dot org
@ 2004-03-31 10:49 ` reichelt at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-03-31 10:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2004-03-31 10:49 -------
The code is invalid: [10.2]/2 states

  The following steps define the result of name lookup in a class scope,
  C.  First, every declaration for the name in the class and in each of
  its base class sub-objects is considered. [...] If the resulting set of
  declarations are not all from sub-objects of the same type, or the set
  has a nonstatic member and includes members from distinct sub-objects,
  there is an ambiguity and the program is ill-formed. Otherwise that set
  is the result of the lookup.

Because the name appears in two base classes, the testcase is invalid.
(The fact that the functions in the testcase have different signatures
doesn't matter at all for name resolution!)


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14790


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-03-31 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30 23:45 [Bug c++/14790] New: C++: ambigous overload compile failure - new case different from 1675 osf at squirrely dot net
2004-03-30 23:53 ` [Bug c++/14790] " bangerth at dealii dot org
2004-03-31 10:49 ` reichelt at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).