public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58119] New: Invalid ambiguous default type conversion with only a single invalid conversion listed.
@ 2013-08-10 12:42 tilps at hotmail dot com
  2013-08-10 17:39 ` [Bug c++/58119] [4.7/4.8/4.9 Regression] " paolo.carlini at oracle dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tilps at hotmail dot com @ 2013-08-10 12:42 UTC (permalink / raw)
  To: gcc-bugs

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.


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

end of thread, other threads:[~2013-08-20 13:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-10 12:42 [Bug c++/58119] New: Invalid ambiguous default type conversion with only a single invalid conversion listed tilps at hotmail dot com
2013-08-10 17:39 ` [Bug c++/58119] [4.7/4.8/4.9 Regression] " paolo.carlini at oracle dot com
2013-08-16 13:49 ` jakub at gcc dot gnu.org
2013-08-18  5:20 ` jason at gcc dot gnu.org
2013-08-20 13:00 ` jason 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).