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

             Bug #: 51222
           Summary: [C++11][SFINAE] Unevaluated combined delete new
                    expression completely broken
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: daniel.krueg...@googlemail.com
                CC: ja...@gcc.gnu.org


The following problem became obvious to me when I recently tried to provide a
both simpler and more general library emulation of is_constructible.

gcc 4.7 20111112 (experimental) in C++11 mode rejects the following code:

//---
template<class T>
struct add_rref {
  typedef T&& type;
};

template<>
struct add_rref<void> {
  typedef void type;
};

template<class T>
typename add_rref<T>::type declval();

template<class T, class U, class =
  decltype(::delete ::new T(declval<U>()))
>
auto f(int) -> char;

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

template<class T, class =
  decltype(::delete ::new T())
>
auto g(int) -> char;

template<class>
auto g(...) -> char(&)[2];

struct C { };

struct A {
  virtual ~A() = 0;
};

struct D1 {
  D1() = delete;
};

struct D2 {
  ~D2() = delete;
};

static_assert(sizeof(g<void>(0)) == 2, "Ouch");
static_assert(sizeof(g<void()>(0)) == 2, "Ouch");
static_assert(sizeof(g<void() const>(0)) == 2, "Ouch");
static_assert(sizeof(g<A>(0)) == 2, "Ouch");
static_assert(sizeof(g<D1>(0)) == 2, "Ouch");
static_assert(sizeof(g<D2>(0)) == 2, "Ouch");
static_assert(sizeof(g<int&>(0)) == 2, "Ouch");
static_assert(sizeof(g<int&&>(0)) == 2, "Ouch");
static_assert(sizeof(g<void(&)()>(0)) == 2, "Ouch");
static_assert(sizeof(g<void(&&)()>(0)) == 2, "Ouch");
static_assert(sizeof(f<void, void>(0)) == 2, "Ouch");
static_assert(sizeof(f<void(), void()>(0)) == 2, "Ouch");
static_assert(sizeof(f<void() const, void() const>(0)) == 2, "Ouch");
static_assert(sizeof(f<int, void>(0)) == 2, "Ouch");
static_assert(sizeof(f<void, int>(0)) == 2, "Ouch");
static_assert(sizeof(f<C, void>(0)) == 2, "Ouch");
static_assert(sizeof(f<C, int>(0)) == 2, "Ouch");
static_assert(sizeof(f<int&, int&>(0)) == 2, "Ouch");
static_assert(sizeof(f<int&&, int&&>(0)) == 2, "Ouch");
static_assert(sizeof(f<void(&)(), void(&)()>(0)) == 2, "Ouch");
static_assert(sizeof(f<void(&&)(), void(&&)()>(0)) == 2, "Ouch");
//---

All static assertions fail, but they shouldn't. This is very unfortunate,
because above test expressions are extremely useful for emulating an effective
variable definition including destruction semantics.

The test code should be accepted.

Reply via email to