Debian Codegraph @

gcc/testsuite/g++.dg/warn/Winfinite-recursion-2.C

raw
1 /* PR middle-end/88232 - Please implement -Winfinite-recursion
2 Test case from PR 87742 (see PR 88232, comment 2.
3 { dg-do compile { target c++11 } }
4 { dg-options "-Wall -Winfinite-recursion" } */
5
6 namespace std
7 {
8 class type_info {
9 public:
10 void k() const;
11 };
12
13 } // namespace std
14
15 using std::type_info;
16
17 template <int a> struct f { static constexpr int c = a; };
18 struct h {
19 typedef int e;
20 };
21
22 template <unsigned long, typename...> struct m;
23 template <unsigned long ab, typename i, typename j, typename... ac>
24 struct m<ab, i, j, ac...> : m<ab + 1, i, ac...> {};
25 template <unsigned long ab, typename j, typename... ac>
26 struct m<ab, j, j, ac...> : f<ab> {};
27 template <unsigned long, typename...> struct n;
28 template <unsigned long ab, typename j, typename... ac>
29 struct n<ab, j, ac...> : n<ab - 1, ac...> {};
30 template <typename j, typename... ac> struct n<0, j, ac...> : h {};
31 template <typename... l> class F {
32 template <typename i> struct I : m<0, i, l...> {};
33 template <int ab> struct s : n<ab, l...> {};
34 static const type_info *const b[];
35 struct G {
36 template <typename ag>
37 operator ag() const // { dg-warning "-Winfinite-recursion" }
38 {
39 return *this;
40 }
41 };
42 unsigned o;
43 G ah;
44
45 public:
46 F();
47 long t() const { return o; }
48 const type_info &m_fn3() const { return *b[o]; }
49 template <int ab> typename s<ab>::e *m_fn4() const {
50 if (o != ab)
51 return nullptr;
52 return ah;
53 }
54 template <int ab> void m_fn5() const {
55 m_fn4<ab>();
56 const type_info &r = m_fn3();
57 r.k();
58 }
59 template <typename i> void u() const { m_fn5<I<i>::c>(); }
60 };
61 template <typename... l> const type_info *const F<l...>::b[] {&typeid(l)...};
62 using am = unsigned char;
63 class H {
64 enum bd : am { be = 2 };
65 using bf = F<int, int, H>;
66 bf ah;
67 template <typename bg> void v() const { ah.u<bg>(); }
68 void w() const;
69 };
70 void H::w() const {
71 bd d = bd(ah.t());
72 switch (d)
73 case be:
74 v<H>();
75 }