public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Martin Staley <staley@t7.lanl.gov> To: gcc-gnats@gcc.gnu.org Cc: mstaley@lanl.gov Subject: c++/5732: g++ not using return type for overload resolution Date: Tue, 19 Feb 2002 23:25:00 -0000 [thread overview] Message-ID: <200202200326.g1K3Qqx27393@pasilla.lanl.gov> (raw) >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
next reply other threads:[~2002-02-20 3:36 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-02-19 23:25 Martin Staley [this message] 2002-02-20 8:59 Phil Edwards 2002-02-20 13:56 pme 2002-02-22 2:31 nathan 2003-01-11 23:36 neroden
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200202200326.g1K3Qqx27393@pasilla.lanl.gov \ --to=staley@t7.lanl.gov \ --cc=gcc-gnats@gcc.gnu.org \ --cc=mstaley@lanl.gov \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).