Automatic date update in version.in
[platform/upstream/binutils.git] / gold / testsuite / gdb_index_test.cc
1 // gdb_index_test.cc -- a test case for the --gdb-index option.
2
3 // Copyright (C) 2012-2014 Free Software Foundation, Inc.
4 // Written by Cary Coutant <ccoutant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 // This source file defines a number of symbols of different forms
24 // to exercise the DWARF scanner in gold.
25
26 namespace
27 {
28 int c1_count;
29 int c2_count;
30 };
31
32 namespace one
33 {
34
35 enum G
36 {
37   G_A,
38   G_B,
39   G_C
40 };
41
42 class c1
43 {
44  public:
45   static int count;
46
47   c1()
48   { ++c1_count; }
49
50   ~c1()
51   {
52     --c1_count;
53   }
54
55   enum E
56   {
57     E_A,
58     E_B,
59     E_C,
60   };
61
62   int
63   val()
64   { return E_A; }
65 };
66
67 c1 c1v;
68 };
69
70 namespace two
71 {
72 const int ci = 3;
73
74 template <typename T>
75 class c2
76 {
77  public:
78   c2(T t)
79     : t_(t)
80   {
81     ++c2_count;
82   }
83
84   ~c2()
85   { --c2_count; }
86
87   T
88   val()
89   { return this->t_; }
90
91   T t_;
92 };
93
94 c2<int> c2v1(1);
95 c2<double> c2v2(2.0);
96 c2<int const*> c2v3(&ci);
97 };
98
99 enum F
100 {
101   F_A,
102   F_B,
103   F_C
104 };
105
106 template <class C>
107 bool
108 check(C* c)
109 { return c->val() == 0; }
110
111 bool
112 check_enum(int i)
113 { return i > 0; }
114
115 struct anonymous_union_container {
116   union {
117     struct astruct {
118       int a;
119     };
120     int b;
121   } u;
122 };
123
124 anonymous_union_container anonymous_union_var;
125
126 #ifdef __GNUC__
127 #define ALWAYS_INLINE __attribute__((always_inline))
128 #else
129 #define ALWAYS_INLINE
130 #endif
131
132 static inline ALWAYS_INLINE int
133 inline_func_1(int i)
134 { return i * 17; }
135
136 int
137 main()
138 {
139   F f = F_A;
140   one::G g = one::G_A;
141   check_enum(f);
142   check_enum(g);
143   check(&one::c1v);
144   check(&two::c2v1);
145   check(&two::c2v2);
146   check(&two::c2v3);
147   anonymous_union_var.u.b = inline_func_1(3) - 51;
148   return anonymous_union_var.u.b;
149 }