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

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