OSDN Git Service

PR c++/55058
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / other / abstract1.C
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).
7
8 struct Abstract { virtual void f() = 0; };  // { dg-message "note" } 
9 struct Complete { void f(); };
10
11
12 /*
13  * TEST 1
14  * Arrays of abstract elements cannot be declared.
15  */
16
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 "" }
27
28 /*
29  * TEST 2
30  * If a pointer to an array of abstract elements is created during template
31  *  instantiation, an error should occur.
32  */
33
34 template <class T> struct K {
35   T (*a)[2];   // { dg-error "abstract class type" }
36 };
37
38 template struct K<Abstract>;  // { dg-message "required" }
39
40
41
42 /*
43  * TEST 3
44  * Deducing an array of abstract elements during type deduction is a silent
45  *  failure (rejects overload).
46  */
47
48 template <bool> struct StaticAssert;
49 template <> struct StaticAssert<true> {};
50
51 typedef char Yes;
52 typedef struct { char x[2]; } No;
53
54 template<typename U> No  is_abstract(U (*k)[1]);
55 template<typename U> Yes is_abstract(...);
56
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;