public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5732: g++ not using return type for overload resolution
@ 2003-01-11 23:36 neroden
  0 siblings, 0 replies; 5+ messages in thread
From: neroden @ 2003-01-11 23:36 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mstaley, nobody

Synopsis: g++ not using return type for overload resolution

State-Changed-From-To: analyzed->closed
State-Changed-By: neroden
State-Changed-When: Sat Jan 11 15:36:33 2003
State-Changed-Why:
    Compiles and runs correctly under 3.4 (mainline) with the new parser.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5732


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

* Re: c++/5732: g++ not using return type for overload resolution
@ 2002-02-22  2:31 nathan
  0 siblings, 0 replies; 5+ messages in thread
From: nathan @ 2002-02-22  2:31 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mstaley, nobody

Synopsis: g++ not using return type for overload resolution

State-Changed-From-To: closed->analyzed
State-Changed-By: nathan
State-Changed-When: Fri Feb 22 02:30:06 2002
State-Changed-Why:
    I think it is a bug. We can't tell until instantiation
    time whether the two conflict or not, and as pointed out
    T::value_type breaks the instantiation when T == int.
    Incidentally, I'll bet you don't get the error if you had
    something like
    template <typename T1, typename T2>
    	void Foo (T1, T2);
    template <typename T2, typename T1>
    	typename T1::value_type Foo (T2, T1);

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5732


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

* Re: c++/5732: g++ not using return type for overload resolution
@ 2002-02-20 13:56 pme
  0 siblings, 0 replies; 5+ messages in thread
From: pme @ 2002-02-20 13:56 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mstaley, nobody

Synopsis: g++ not using return type for overload resolution

State-Changed-From-To: open->closed
State-Changed-By: pme
State-Changed-When: Wed Feb 20 13:44:29 2002
State-Changed-Why:
    User error.  Functions differing only in their return types
    may not be overloaded.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5732


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

* Re: c++/5732: g++ not using return type for overload resolution
@ 2002-02-20  8:59 Phil Edwards
  0 siblings, 0 replies; 5+ messages in thread
From: Phil Edwards @ 2002-02-20  8:59 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/5732; it has been noted by GNATS.

From: Phil Edwards <phil@jaj.com>
To: mstaley@lanl.gov
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/5732: g++ not using return type for overload resolution
Date: Wed, 20 Feb 2002 11:07:34 -0500

 On Tue, Feb 19, 2002 at 08:26:52PM -0700, Martin Staley wrote:
 > 
 >      template<class T>
 >      T fun(const T &)
 >      {
 >         std::cout << "foo" << std::endl;
 >         return 0;
 >      }
 > 
 >      template<class T>
 >      typename T::value_type fun(const T &)
 >      {
 >         std::cout << "bar" << std::endl;
 >         return 0;
 >      }
 
 Not a bug.
 
     Function declarations that differ only in the return type cannot
     be overloaded.
 
 Thus sayeth the standard, [13.1]/2.
 
 


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

* c++/5732: g++ not using return type for overload resolution
@ 2002-02-19 23:25 Martin Staley
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Staley @ 2002-02-19 23:25 UTC (permalink / raw)
  To: gcc-gnats; +Cc: mstaley


>Number:         5732
>Category:       c++
>Synopsis:       g++ not using return type for overload resolution
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 19 19:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        3.0.3
>Organization:
	Los Alamos National Laboratory
>Environment:
System: Linux pasilla.lanl.gov 2.4.3-12smp #1 SMP Fri Jun 8 14:38:50 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.0.3/configure --prefix=/packages/gcc/gcc-3.0.3
>Description:
I ran across the following problem using g++ 3.0.3, and didn't find any mention
of it on http://www.gnu.org/software/gcc/bugs.html.  The following is (I think!)
legal C++:

     // file bug.cc
     #include <iostream>

     template<class T>
     T fun(const T &)
     {
        std::cout << "foo" << std::endl;
        return 0;
     }

     template<class T>
     typename T::value_type fun(const T &)
     {
        std::cout << "bar" << std::endl;
        return 0;
     }

     int main(void)
     {
        fun(1);
     }

I believe this should compile and print "foo".  But compiling with "g++ bug.cc"
produces the following diagnostic:

     bug.cc:15: new declaration `template<class T> typename T::value_type fun(const
        T&)'
     bug.cc:7: ambiguates old declaration `template<class T> T fun(const T&)'

Under older C++ rules, the two declarations would indeed conflict because the
formal parameters are exactly the same: const T & for both versions of fun().
But, Standard C++ as I understand it also uses a function template's return type
when determining if it's a match for a particular call.  If the return type
doesn't "work", then it's not considered a possible match.

E.g., in the above code: "typename T::value_type" makes no sense for T=int,
so the second version of fun() doesn't work.  Thus the first version of fun()
should be used.  That's the way it works with the EDG front-end, and I've
examined the standard and EDG is apparently correct.  If I'm right about this
being a bug then you're probably aware of it already, but I figured I should
report it.

Since the "Reporting Bugs" web page requests it: gcc -v gives

     Reading specs from /packages/gcc/gcc-3.0.3/lib/gcc-lib/i686-pc-linux-gnu/3.0.3/specs
     Configured with: ../gcc-3.0.3/configure --prefix=/packages/gcc/gcc-3.0.3
     Thread model: single
     gcc version 3.0.3

Let me know if you need any further information.

Martin
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
 	Martin Staley


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

end of thread, other threads:[~2003-01-11 23:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-11 23:36 c++/5732: g++ not using return type for overload resolution neroden
  -- strict thread matches above, loose matches on Subject: below --
2002-02-22  2:31 nathan
2002-02-20 13:56 pme
2002-02-20  8:59 Phil Edwards
2002-02-19 23:25 Martin Staley

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).