aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/ipa/devirt-29.C
blob: b4f24a1044ca7bb4c8a9758a50b7733db8166105 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* { dg-do run { target c++11 } } */
/* There is a devirtualizable call. In PR60306 we deduced wrong target to cxa_pure_virtual.
   For gcc 4.10 we temporarily disable the devirtualization.  */
/* { dg-options "-O3"  } */

#include <vector>

using std::vector;

class Object 
{
public:

  virtual Object* clone() const =0;

  virtual int type() const {return 0;}

  Object& operator=(const Object&) {return *this;}

  Object() {}
  Object(const Object&) {}
  virtual ~Object() {}
};

Object* f(const Object&o)
{
  return o.clone();
}

template<typename T>
class Box: public Object, public T
{
public:
  Box<T>* clone() const {return new Box<T>(*this);}

  Box<T>& operator=(const Box<T>& t)
  {
    T::operator=(t);
    return *this;
  }

  Box<T>& operator=(const T& t)
  {
    T::operator=(t);
    return *this;
  }

  Box() = default;
  Box(const Box<T>&) = default;
  explicit Box(const T& t):T(t) {}
};

template <typename T>
using Vector = Box<vector<T>>;

typedef Vector<int> OVector;

OVector edges_connecting_to_node(int n)
{
  OVector branch_list_;
  for(int i=0;i<n;i++)
    branch_list_.push_back(i);

  return branch_list_;
}

int main(int argc,char* argv[])
{ 
  for(int n=0; n < argc; n++)
  {
    auto x = edges_connecting_to_node(1);
    x.clone();
    f(x);
  }
}