summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/torture/pr39417.C
blob: b7bbb88b7845634178215a8ea346c7d0acd879c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// { dg-do run }

#include <vector>

std::vector <int>
sequence(int l, int n)
{
  std::vector <int> ret;
  for(int i=n;i<=100;i++)
    {
      if(i%2==0)
	{
	  if(l%i==i/2)
	    {
	      int init =l/i-i/2+1;
	      if(init>=0)
		{
		  for(int j=0;j<i;j++)
		    {
		      ret.push_back(init);
		      init ++;
		    }
		  break;
		}
	    }
	}
      else
	{
	  if(l%i==0)
	    {
	      int init =l/i-i/2;
	      if(init>=0)
		{
		  for(int j=0;j<i;j++)
		    {
		      ret.push_back(init);
		      init ++;
		    }
		  break;
		}
	    }
	}
    }
  return ret;
}
extern "C" void abort (void);
int main()
{
  std::vector<int> res = sequence(18, 2);
  if (res.size () != 3
      || res[0] != 5
      || res[1] != 6
      || res[2] != 7)
    abort ();
  return 0;
}