Skip to content

Obj-C++ regression: overloading isn't preferring the conversion-to-superclass over the conversion-to-void* #10107

@nico

Description

@nico
Bugzilla Link 9735
Resolution FIXED
Resolved on Apr 15, 2011 15:46
Version trunk
OS All
CC @DougGregor

Extended Description

Consider:

#import <AppKit/AppKit.h>

#include
using namespace std;

template
inline void g(std::ostream* os, const T& val) {
*os << val;
}

std::ostream& operator<<(std::ostream& out, const NSObject* obj) {
return out << "asdf";
}

void f(ostream& out, const NSEvent* e) {
g(&out, e);
}

This compiles fine in gcc and used to compile fine in clang before r129339. But now clang complains:

test.mm:8:7: error: use of overloaded operator '<<' is ambiguous (with operand types 'std::ostream' (aka 'basic_ostream') and 'const NSEvent *const')
*os << val;

test.mm:16:3: note: in instantiation of function template specialization 'g<const NSEvent *>' requested here
g(&out, e);
^
/usr/include/c++/4.2.1/ostream:228:7: note: candidate function
    operator<<(const void* __p)
    ^
test.mm:11:15: note: candidate function
std::ostream& operator<<(std::ostream& out, const NSObject* obj) {
            ^
/usr/include/c++/4.2.1/ostream:176:7: note: candidate function
    operator<<(bool __n)
    ^
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions