public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/36486]  New: g++ accepts code with ambiguous overloading
@ 2008-06-10 14:41 richard-gccbugzilla at metafoo dot co dot uk
  2008-06-10 14:51 ` [Bug c++/36486] " richard-gccbugzilla at metafoo dot co dot uk
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: richard-gccbugzilla at metafoo dot co dot uk @ 2008-06-10 14:41 UTC (permalink / raw)
  To: gcc-bugs

g++ (at least versions 3.3.5, 3.4.4 and 4.1.1) accepts the following code,
which I think is ill-formed:


template<typename T> struct F {};

template<typename C, typename R>
int f(R (C::*f)() const, const F<R> &n = F<R>()) { return 0; } // f0

template<typename C, typename R>
int f(const R &(C::*f)() const, const F<R> &n = F<R>()) { return 1; } // f1

struct X { const X &foo() const { return *this; } };

int main() { return f(&X::foo); }


Here, g++ is presumably deciding that f1 is more specialized than f0, despite
f0's arguments not being deducible from f1 (indeed, there is no pair of
argument types (T1, T2) which both f0 and f1 accept).

EDG's frontend rejects the above code.


-- 
           Summary: g++ accepts code with ambiguous overloading
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: richard-gccbugzilla at metafoo dot co dot uk


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


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

* [Bug c++/36486] g++ accepts code with ambiguous overloading
  2008-06-10 14:41 [Bug c++/36486] New: g++ accepts code with ambiguous overloading richard-gccbugzilla at metafoo dot co dot uk
@ 2008-06-10 14:51 ` richard-gccbugzilla at metafoo dot co dot uk
  2008-06-10 21:33 ` peterbindels at gmail dot com
  2008-06-11 12:59 ` richard-gccbugzilla at metafoo dot co dot uk
  2 siblings, 0 replies; 4+ messages in thread
From: richard-gccbugzilla at metafoo dot co dot uk @ 2008-06-10 14:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from richard-gccbugzilla at metafoo dot co dot uk  2008-06-10 14:51 -------
FWIW, Microsoft's recent compilers agree that this is ill-formed also.


-- 


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


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

* [Bug c++/36486] g++ accepts code with ambiguous overloading
  2008-06-10 14:41 [Bug c++/36486] New: g++ accepts code with ambiguous overloading richard-gccbugzilla at metafoo dot co dot uk
  2008-06-10 14:51 ` [Bug c++/36486] " richard-gccbugzilla at metafoo dot co dot uk
@ 2008-06-10 21:33 ` peterbindels at gmail dot com
  2008-06-11 12:59 ` richard-gccbugzilla at metafoo dot co dot uk
  2 siblings, 0 replies; 4+ messages in thread
From: peterbindels at gmail dot com @ 2008-06-10 21:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from peterbindels at gmail dot com  2008-06-10 21:32 -------
It's still warning free on 4.3.1 (except with all turned on, when ti complains
about unused parameters but nothing else).

As far as I can tell the second template matches the subset of the matches for
the first template where R would be an const ? &, with the second parameter
matching a different but still default constructed type. It's not ambiguous
because of the const at least.

I don't see why this would not work? Do you have an std reference for why this
would be ill-formed?


-- 

peterbindels at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peterbindels at gmail dot
                   |                            |com


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


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

* [Bug c++/36486] g++ accepts code with ambiguous overloading
  2008-06-10 14:41 [Bug c++/36486] New: g++ accepts code with ambiguous overloading richard-gccbugzilla at metafoo dot co dot uk
  2008-06-10 14:51 ` [Bug c++/36486] " richard-gccbugzilla at metafoo dot co dot uk
  2008-06-10 21:33 ` peterbindels at gmail dot com
@ 2008-06-11 12:59 ` richard-gccbugzilla at metafoo dot co dot uk
  2 siblings, 0 replies; 4+ messages in thread
From: richard-gccbugzilla at metafoo dot co dot uk @ 2008-06-11 12:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from richard-gccbugzilla at metafoo dot co dot uk  2008-06-11 12:58 -------
I'm not 100% certain that g++ is at fault. Given that icc, Comeau and MS all
reject it, I'm inclined to think that g++ is probably the one which gets this
wrong, so I've raised this here first.

This hinges on whether f0 and f1 are ordered by the standard partial ordering
on function templates. It appears superficially that they are not, since from
the arguments to f1 you cannot deduce the template parameters of f0, nor vice
versa. However, it appears to depend on interpretation of [temp.deduct.type]/5,
which says that "The non-deduced contexts are: [...] A template parameter used
in the parameter type of a function parameter that has a default argument that
is being used in the call for which argument deduction is being done". I'm not
sure whether that applies here, but if it does, perhaps that makes f1 more
specialized than f0, and this is a bug in all the other compilers.


-- 


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


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

end of thread, other threads:[~2008-06-11 12:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-10 14:41 [Bug c++/36486] New: g++ accepts code with ambiguous overloading richard-gccbugzilla at metafoo dot co dot uk
2008-06-10 14:51 ` [Bug c++/36486] " richard-gccbugzilla at metafoo dot co dot uk
2008-06-10 21:33 ` peterbindels at gmail dot com
2008-06-11 12:59 ` richard-gccbugzilla at metafoo dot co dot uk

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