2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / other / abstract1.C
blob53d767acd453026750d5d4807e1af647b186275b
1 // { dg-do compile }
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-message "note" } 
9 struct Complete { void f(); };
13  * TEST 1
14  * Arrays of abstract elements cannot be declared.
15  */
17 Abstract a0[2];        // { dg-error "" }
18 Abstract (*a1)[2];     // { dg-error "" }
19 Abstract (**a2)[2];    // { dg-error "" }
20 Abstract (***a3)[2];   // { dg-error "" }
21 Abstract *a4;
22 Abstract *a5[2];
23 Abstract (*a6[2])[2];  // { dg-error "" }
24 Abstract **a7[2];
25 Abstract *(*a8[2])[2];  
26 Abstract (**a9[2])[2]; // { dg-error "" }
29  * TEST 2
30  * If a pointer to an array of abstract elements is created during template
31  *  instantiation, an error should occur.
32  */
34 template <class T> struct K {
35   T (*a)[2];   // { dg-error "abstract class type" }
38 template struct K<Abstract>;  // { dg-message "required" }
43  * TEST 3
44  * Deducing an array of abstract elements during type deduction is a silent
45  *  failure (rejects overload).
46  */
48 template <bool> struct StaticAssert;
49 template <> struct StaticAssert<true> {};
51 typedef char Yes;
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;