1 // { dg-do run }
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 
6 class XMemory
7 {
8 public:
9   void * operator new (size_t size);
10   void operator delete (void *p);
11 
12 protected:
XMemory()13   XMemory () {}
14 
~XMemory()15   virtual ~XMemory() {}
16 };
17 
18 class XSerializable
19 {
20 public:
~XSerializable()21   virtual ~XSerializable () {};
22 
23   virtual bool isSerializable() const = 0;
24   virtual void serialize () = 0;
25 
26 protected:
XSerializable()27   XSerializable() {};
28 
29 };
30 
31 class Grammar: public XSerializable, public XMemory
32 {
33 public:
34   enum GrammarType {
35     DTDGrammarType,
36     SchemaGrammarType,
37     OtherGrammarType,
38     Unknown
39   };
40 
~Grammar()41   virtual ~Grammar() {}
42 
43   virtual GrammarType getGrammarType() const = 0;
44   virtual bool getValidated() const = 0;
45 
46   virtual bool isSerializable() const;
47   virtual void serialize ();
48 
49 protected:
Grammar()50   Grammar() {};
51 
52 };
53 
54 class SchemaGrammar : public Grammar
55 {
56 public:
57 
SchemaGrammar()58   SchemaGrammar () :  Grammar(), elemID(10) { fValidated = true; }
59 
~SchemaGrammar()60   virtual ~SchemaGrammar() {}
61 
62   virtual Grammar::GrammarType getGrammarType() const;
63   virtual bool getValidated() const;
64 
65   virtual bool isSerializable () const;
66   virtual void serialize ();
67 
68 private:
69   const unsigned int elemID;
70   bool fValidated;
71 
72 };
73 
74 class OtherGrammar : public Grammar
75 {
76 public:
77 
OtherGrammar()78   OtherGrammar () :  Grammar(), elemID(10) { fValidated = true; }
79 
~OtherGrammar()80   virtual ~OtherGrammar() {}
81 
82   virtual Grammar::GrammarType getGrammarType() const;
83   virtual bool getValidated() const;
84 
85   virtual bool isSerializable () const;
86   virtual void serialize ();
87 
88 private:
89   const unsigned int elemID;
90   bool fValidated;
91 
92 };
93 
94 void
serialize()95 Grammar::serialize ()
96 {
97   printf ("in Grammar::serialize\n");
98 }
99 
100 bool
isSerializable() const101 Grammar::isSerializable () const
102 {
103   return true;
104 }
105 
106 bool
isSerializable() const107 SchemaGrammar::isSerializable () const
108 {
109   return true;
110 }
111 
112 void
serialize()113 SchemaGrammar::serialize ()
114 {
115   printf ("in SchemaGrammar::serialize\n");
116 }
117 
118 Grammar::GrammarType
getGrammarType() const119 SchemaGrammar::getGrammarType() const {
120   return Grammar::SchemaGrammarType;
121 }
122 
123 bool
getValidated() const124 SchemaGrammar::getValidated () const
125 {
126   return fValidated;
127 }
128 
129 void *
operator new(size_t size)130 XMemory::operator new (size_t size)
131 {
132   return malloc (size);
133 }
134 
135 void
operator delete(void * p)136 XMemory::operator delete (void *p)
137 {
138 }
139 
140 bool
isSerializable() const141 OtherGrammar::isSerializable () const
142 {
143   return false;
144 }
145 
146 void
serialize()147 OtherGrammar::serialize ()
148 {
149   printf ("in OtherGrammar::serialize\n");
150 }
151 
152 Grammar::GrammarType
getGrammarType() const153 OtherGrammar::getGrammarType() const {
154   return Grammar::OtherGrammarType;
155 }
156 
157 bool
getValidated() const158 OtherGrammar::getValidated () const
159 {
160   return fValidated;
161 }
162 
163 int
main(int argc,char ** argv)164 main (int argc, char **argv)
165 {
166   SchemaGrammar sPtr;
167   OtherGrammar oPtr;
168   Grammar &sGrammar = sPtr;
169 
170   for (int i = 0; i < 2; ++i)
171     {
172       if (i == 0)
173 	sGrammar = oPtr;
174       else
175 	sGrammar = sPtr;
176 
177       if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType ||
178 	  sGrammar.getValidated ())
179 	printf ("if condition was true.\n");
180       else
181 	printf ("if condition was false.\n");
182     }
183 
184   return 0;
185 }
186