http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48535
Summary: [C++0x][SFINAE] Hard errors during
list-value-initialization
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
In several situations during list-initialization with an empty braced list gcc
produces either hard errors:
a) abstract class
b) function type
c) class type with deleted destructor
d) binding a temporary to a reference to non-const
e) binding a temporary to a reference to const
or accepts ill-formed code:
f) attempting to produce a zero-length array
//-----------------
template<class T,
class = decltype(T{})
>
char f(int);
template<class>
char (&f(...))[2];
struct A { virtual ~A() = 0; };
struct NonDtor {
~NonDtor() = delete;
};
static_assert(sizeof(f<A>(0)) != 1, "Error"); // (a)
static_assert(sizeof(f<void()>(0)) != 1, "Error"); // (b)
static_assert(sizeof(f<NonDtor>(0)) != 1, "Error"); // (c)
static_assert(sizeof(f<int&>(0)) != 1, "Error"); // (d)
static_assert(sizeof(f<const int&>(0)) == 1, "Error"); // (e)
static_assert(sizeof(f<int[]>(0)) != 1, "Error"); // (f)
//-----------------
(a): "error: cannot allocate an object of abstract type ‘A’ because the
following virtual functions are pure within ‘A’"
(b): "error: compound literal of non-object type ‘void()’"
(c): "error: use of deleted function ‘NonDtor::~NonDtor()’"
(d): "error: compound literal of non-object type ‘int&’"
(e): "error: compound literal of non-object type ‘const int&’"
(f): Assertion triggers!