OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [warn/] [Warray-bounds-4.C] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.