Consider the folowing:

    class XXX {

    public:

        XXX(char) {}
        template <typename T> XXX(T) = delete;
    };

    fprintf(stderr, "ic<char>::value = %i\n",
std::is_convertible<char, XXX>::value);
    fprintf(stderr, "ic<double>::value = %i\n",
std::is_convertible<double, XXX>::value);

The code above doesn't compile on gcc 4.6:

In file included from /home/piotr.wyderski/f1/base/common.h:9:0,
                 from /home/piotr.wyderski/f1/main.cpp:8:
/opt/gcc-trunk-old2/bin/../lib/gcc/i686-pc-cygwin/4.6.0/include/c++/type_traits:
 In instantiation of `const bool std::__is_convertible_helper<double, XXX, false
>::__value':
/opt/gcc-trunk-old2/bin/../lib/gcc/i686-pc-cygwin/4.6.0/include/c++/type_traits:
309:12:   instantiated from `std::is_convertible<double, XXX>'
/home/piotr.wyderski/f1/main.cpp:219:81:   instantiated from here
/home/piotr.wyderski/f1/main.cpp:186:31: error: deleted function `XXX::XXX(T) [w
ith T = double]'
/opt/gcc-trunk-old2/bin/../lib/gcc/i686-pc-cygwin/4.6.0/include/c++/type_traits:
302:71: error: used here

IMO it should result in an executable program which prints:

ic<char>::value =1
ic<double>::value = 0

as double is obviously not convertible to XXX -- the  "template
<typename T> XXX(T) = delete;"
idiom: is very similar to an example from the N2346 proposal:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm

"Removing dangerous conversions is as important as removing undesired
language defaults.

    struct type
    {
        type( long long ); // can initialize with an long long
        type( long ) = delete; // but not anything less
    };
    extern void bar( type, long long ); // and the same for bad overloads
    void bar( type, long ) = delete; // of free functions
"

Should I file a bug report or is it broken by design?

A proposed fix is to remove the current template-based detector in the
standard library and provide
a built-in function __is_convertible which would check such corner
cases in a much smarter way
than is possible with templates:

http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Traits.html#Type-Traits

    Best regards,
    Piotr Wyderski

Reply via email to