public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators
@ 2011-09-06 17:21 malaperle at omnialabs dot net
  2011-11-17 18:06 ` [Bug c++/50306] ambiguous templated conversion operators accepted malaperle at omnialabs dot net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: malaperle at omnialabs dot net @ 2011-09-06 17:21 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50306
           Summary: g++ accepts code with ambiguous, templated conversion
                    operators
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: malaperle@omnialabs.net


This code does not generate an error or warning:

class A{};
class B : public A {};

template <class T> class SmartPtr{
public:
    template<typename OtherT> operator const SmartPtr<OtherT>&() const;

    template<typename OtherT> operator SmartPtr<OtherT>() const;
};

void func(SmartPtr<A>) {
}

int main() {
    SmartPtr<B> b;
    func(b); // this should be ambiguous?
}

But it is an error with MSVC 10 and Clang 2.8.

If the templates on the operators are removed, it also becomes ambiguous with
gcc:

class A {};
class B : public A {};

template <class T> class SmartPtr {
public:
    operator const SmartPtr<A>&() const;
    operator SmartPtr<A>() const;
};

void func(SmartPtr<A>) {
}

int main() {
    SmartPtr<B> b;
    func(b); // func is ambiguous
}


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

* [Bug c++/50306] ambiguous templated conversion operators accepted
  2011-09-06 17:21 [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators malaperle at omnialabs dot net
@ 2011-11-17 18:06 ` malaperle at omnialabs dot net
  2011-11-17 19:05 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: malaperle at omnialabs dot net @ 2011-11-17 18:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Marc-Andre Laperle <malaperle at omnialabs dot net> 2011-11-17 18:00:27 UTC ---
I have never worked with the GCC source code before, any pointers to where I
should start to look to fix this issue? Thanks!


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

* [Bug c++/50306] ambiguous templated conversion operators accepted
  2011-09-06 17:21 [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators malaperle at omnialabs dot net
  2011-11-17 18:06 ` [Bug c++/50306] ambiguous templated conversion operators accepted malaperle at omnialabs dot net
@ 2011-11-17 19:05 ` manu at gcc dot gnu.org
  2011-11-19  8:12 ` malaperle at omnialabs dot net
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2011-11-17 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-11-17 18:27:00 UTC ---
(In reply to comment #1)
> I have never worked with the GCC source code before, any pointers to where I
> should start to look to fix this issue? Thanks!

http://gcc.gnu.org/wiki/DebuggingGCC

You could put a breakpoint for the second testcase in error(). Find out why the
error triggers, and then find out what is the difference with the first
testcase. In any case, the relevant code is in gcc/cp/. I hope you don't get
scared by the looks. It ain't pretty.

However, this seems to be fixed in trunk (at least revision 180166):

manuel@gcc12:~$ ~/trunk/180166/build/gcc/cc1plus pr50306.cc
 void func(SmartPtr<A>) int main()
pr50306.cc:15:9: error: conversion from ‘SmartPtr<B>’ to ‘SmartPtr<A>’ is
ambiguous
pr50306.cc:14:15: note: candidates are:
pr50306.cc:7:3: note: SmartPtr<T>::operator SmartPtr<A>() const [with T = B]
pr50306.cc:6:3: note: SmartPtr<T>::operator const SmartPtr<A>&() const [with T
= B]
pr50306.cc:10:6: error:   initializing argument 1 of ‘void func(SmartPtr<A>)’

Maybe you should try 4.6.2?


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

* [Bug c++/50306] ambiguous templated conversion operators accepted
  2011-09-06 17:21 [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators malaperle at omnialabs dot net
  2011-11-17 18:06 ` [Bug c++/50306] ambiguous templated conversion operators accepted malaperle at omnialabs dot net
  2011-11-17 19:05 ` manu at gcc dot gnu.org
@ 2011-11-19  8:12 ` malaperle at omnialabs dot net
  2011-11-19 12:46 ` paolo.carlini at oracle dot com
  2011-11-19 13:57 ` manu at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: malaperle at omnialabs dot net @ 2011-11-19  8:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marc-Andre Laperle <malaperle at omnialabs dot net> 2011-11-19 05:38:32 UTC ---
I tried 4.6.2, r181503 and r180166 and they all compiled the sample code
without error. Do you have any local changes or special parameters that made it
not compile?


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

* [Bug c++/50306] ambiguous templated conversion operators accepted
  2011-09-06 17:21 [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators malaperle at omnialabs dot net
                   ` (2 preceding siblings ...)
  2011-11-19  8:12 ` malaperle at omnialabs dot net
@ 2011-11-19 12:46 ` paolo.carlini at oracle dot com
  2011-11-19 13:57 ` manu at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-11-19 12:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-11-19 12:11:05 UTC ---
Yes, I confirm the issue doesn't seem fixed neither mainline nor 4_6-branch.


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

* [Bug c++/50306] ambiguous templated conversion operators accepted
  2011-09-06 17:21 [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators malaperle at omnialabs dot net
                   ` (3 preceding siblings ...)
  2011-11-19 12:46 ` paolo.carlini at oracle dot com
@ 2011-11-19 13:57 ` manu at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2011-11-19 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-11-19
     Ever Confirmed|0                           |1

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-11-19 12:46:13 UTC ---
You are right, it seems I tested the second example by mistake.


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

end of thread, other threads:[~2011-11-19 12:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-06 17:21 [Bug c++/50306] New: g++ accepts code with ambiguous, templated conversion operators malaperle at omnialabs dot net
2011-11-17 18:06 ` [Bug c++/50306] ambiguous templated conversion operators accepted malaperle at omnialabs dot net
2011-11-17 19:05 ` manu at gcc dot gnu.org
2011-11-19  8:12 ` malaperle at omnialabs dot net
2011-11-19 12:46 ` paolo.carlini at oracle dot com
2011-11-19 13:57 ` manu at gcc dot gnu.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).