1 // { dg-do compile }
2 // { dg-options "-O2 -Warray-bounds" }
3 // { dg-skip-if "" { *-*-aix* } }
4 
5 class String
6 {
7 public:
8   virtual unsigned long length() const = 0;
9   virtual char get(unsigned long index) const = 0;
10   virtual void set(unsigned long index, char value) = 0;
11   virtual char& operator[] (unsigned long value) = 0;
~String()12   virtual ~String() {};
13 };
14 
15 template<unsigned long size> class FixedString : public String
16 {
17 private:
18   char contents[size];
19 
20 public:
length()21   virtual unsigned long length() const { return size; }
get(unsigned long index)22   virtual char get(unsigned long index) const { return contents[index]; }
set(unsigned long index,char value)23   virtual void set(unsigned long index, char value) { contents[index] = value; }
24   virtual char& operator[] (unsigned long index) { return contents[index]; }
25 
FixedString()26   FixedString() { contents[0] = '\0'; } // { dg-warning "\\\[-Warray-bounds" }
27 };
28 
29 void print_length (const String& string);
30 
main()31 int main()
32 {
33   const FixedString<0> empty;
34 
35   print_length(empty);
36 
37   return 0;
38 }
39