[Bug c++/48450] New: [C++0x][SFINAE] Hard errors with static_cast expressions

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Tue Apr 5 06:41:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48450

           Summary: [C++0x][SFINAE] Hard errors with static_cast
                    expressions
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com
                CC: jason@redhat.com


The following families of expressions give hard compiler errors in a SFINAE
context:

     a) any T => abstract class
     b) cv void* => T* (T != void)
     c) cv Base* => Derived*
     d) cv T Derived::* => T Base::*
     e) cv void => T (T is a class type)
     f) Scoped enum => bool

The following code should be well-formed, but is not:

#include <utility> // for declval

template<class To, class From,
 class = decltype(static_cast<To>(std::declval<From>()))
>
char f(int);

template<class, class>
char (&f(...))[2];

struct A { virtual ~A() = 0; };
struct B {};
struct D : B {};
enum class SE {};

static_assert(sizeof(f<A, int>(0)) != 1, "Error"); // a
static_assert(sizeof(f<int*, const void*>(0)) != 1, "Error"); // b
static_assert(sizeof(f<D*, const B*>(0)) != 1, "Error"); // c
static_assert(sizeof(f<int B::*, const int D::*>(0)) != 1, "Error"); // d
static_assert(sizeof(f<B, void>(0)) != 1, "Error"); // e
static_assert(sizeof(f<bool, SE>(0)) == 1, "Error"); // f

a) "error: cannot allocate an object of abstract type 'A' because the
following virtual functions are pure within 'A': virtual A::~A()"
b) "error: static_cast from type 'const void*' to type 'int*' casts
away qualifiers"
c) "error: static_cast from type 'const B*' to type 'D*' casts away qualifiers"
d) "error: static_cast from type 'const int D::*' to type 'int B::*'
casts away qualifiers"
e) "error: invalid use of void expression"
f) "error: invalid operands of types 'SE' and 'int' to binary 'operator!='"



More information about the Gcc-bugs mailing list