2 // Contributed by <giovannibajo at gcc dot gnu dot org>,
3 // <pavel_vozenilek at hotmail dot com>,
4 // <bangerth at dealii dot org>
5 // c++/9256: Make sure that a pointer to an array of abstract elements
6 // cannot be created, not even during template substitution (DR337).
8 struct Abstract { virtual void f() = 0; }; // { dg-error "" }
9 struct Complete { void f(); };
14 * Arrays of abstract elements cannot be declared.
17 Abstract a0[2]; // { dg-error "" }
18 Abstract (*a1)[2]; // { dg-error "" }
19 Abstract (**a2)[2]; // { dg-error "" }
20 Abstract (***a3)[2]; // { dg-error "" }
23 Abstract (*a6[2])[2]; // { dg-error "" }
25 Abstract *(*a8[2])[2];
26 Abstract (**a9[2])[2]; // { dg-error "" }
30 * If a pointer to an array of abstract elements is created during template
31 * instantiation, an error should occur.
34 template <class T> struct K {
35 T (*a)[2]; // { dg-error "abstract class type" }
38 template struct K<Abstract>; // { dg-error "from here" }
44 * Deducing an array of abstract elements during type deduction is a silent
45 * failure (rejects overload).
48 template <bool> struct StaticAssert;
49 template <> struct StaticAssert<true> {};
52 typedef struct { char x[2]; } No;
54 template<typename U> No is_abstract(U (*k)[1]);
55 template<typename U> Yes is_abstract(...);
57 StaticAssert<sizeof(is_abstract<Abstract>(0)) == sizeof(Yes)> b1;
58 StaticAssert<sizeof(is_abstract<Complete>(0)) == sizeof(No)> b2;
59 StaticAssert<sizeof(is_abstract<int>(0)) == sizeof(No)> b3;