This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58119] New: Invalid ambiguous default type conversion with only a single invalid conversion listed.
- From: "tilps at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 10 Aug 2013 12:42:00 +0000
- Subject: [Bug c++/58119] New: Invalid ambiguous default type conversion with only a single invalid conversion listed.
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58119
Bug ID: 58119
Summary: Invalid ambiguous default type conversion with only a
single invalid conversion listed.
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tilps at hotmail dot com
'Minimal' test case:
template <class type>
class Silly {
public:
Silly(type *value) {
data_ = value;
}
operator type*() const {
return data_;
}
template <class other>
operator Silly<other>() const {
return Silly<other>(data_);
}
private:
type *data_;
};
int main() {
Silly<int> a(nullptr);
delete a;
}
Fails giving:
test.cc:20:10: error: ambiguous default type conversion from 'Silly<int>'
delete a;
^
test.cc:20:10: error: candidate conversions include 'template<class other>
Silly<type>::operator Silly<other>() const [with other = other; type = int]'
test.cc:20:10: error: type 'class Silly<int>' argument given to 'delete',
expected pointer
I believe that this code should be considered valid, the only valid type
conversion is via the operator type *() which then converts to void* for the
delete operator. I don't see any way that Silly<anything> could be considered
convertible, except via operator type *() - and as far as I was aware, only a
single implicit cast operator is allowed to be considered in a type conversion
chain.
Interestingly, the valid type conversion is not mentioned as a candidate, and
the candidate mentioned does not specify which template parameter type it would
use for the 'other' template parameter.
Ultimately this is a bit of a strange example - I was trying to resurrect some
legacy code with a particularly dumb (but heavily used) 'smart pointer' type.
But this code did work, at least as recently as 4.6 - and probably back before
3.2.