]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/local-static.c
Make "p S::method() const::static_var" work too
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / local-static.c
CommitLineData
858be34c
PA
1/* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2002-2017 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18struct aggregate
19{
20 int i1;
21 int i2;
22 int i3;
23};
24
25void keepalive_float (double *var) { }
26void keepalive_int (int *var) { }
27void keepalive_aggregate (struct aggregate *var) { }
28
29#define PREFIXIFY(PREFIX, VAR) \
30 PREFIX ## _ ## VAR
31
32#define DEF_STATICS(PREFIX) \
33 static int PREFIXIFY(PREFIX, s_var_int) = 4; \
34 static double PREFIXIFY(PREFIX, s_var_float) = 3.14f; \
35 static struct aggregate PREFIXIFY(PREFIX, s_var_aggregate) \
36 = { 1, 2, 3 }; \
37 \
38 keepalive_int (&PREFIXIFY(PREFIX, s_var_int)); \
39 keepalive_float (&PREFIXIFY(PREFIX, s_var_float)); \
40 keepalive_aggregate (&PREFIXIFY(PREFIX, s_var_aggregate));
41
42#ifdef __cplusplus
43
44struct S
45{
46 void inline_method ()
47 {
48 DEF_STATICS (S_IM);
49 }
50 static void static_inline_method ()
51 {
52 DEF_STATICS (S_SIM);
53 }
54
55 void method ();
3693fdb3
PA
56 void method () const;
57 void method () volatile;
58 void method () volatile const;
59
858be34c
PA
60 static void static_method ();
61};
62
63S s;
3693fdb3
PA
64const S c_s = {};
65volatile S v_s = {};
66const volatile S cv_s = {};
858be34c
PA
67
68void
69S::method ()
70{
71 DEF_STATICS (S_M);
72}
73
3693fdb3
PA
74void
75S::method () const
76{
77 DEF_STATICS (S_M_C);
78}
79
80void
81S::method () volatile
82{
83 DEF_STATICS (S_M_V);
84}
85
86void
87S::method () const volatile
88{
89 DEF_STATICS (S_M_CV);
90}
91
858be34c
PA
92void
93S::static_method ()
94{
95 DEF_STATICS (S_SM);
96}
97
98template <typename T>
99struct S2
100{
101 void method ();
102 static void static_method ();
103
104 void inline_method ()
105 {
106 DEF_STATICS (S2_IM);
107 }
108
109 static void static_inline_method ()
110 {
111 DEF_STATICS (S2_SIM);
112 }
113};
114
115template<typename T>
116void
117S2<T>::method ()
118{
119 DEF_STATICS (S2_M);
120}
121
122template<typename T>
123void
124S2<T>::static_method ()
125{
126 DEF_STATICS (S2_SM);
127}
128
129S2<int> s2;
130
131#endif
132
133void
134free_func (void)
135{
136 DEF_STATICS (FF);
137}
138
139static inline void
140free_inline_func (void)
141{
142 DEF_STATICS (FIF);
143}
144
145int
146main ()
147{
148 for (int i = 0; i < 1000; i++)
149 {
150 free_func ();
151 free_inline_func ();
152
153#ifdef __cplusplus
154 s.method ();
3693fdb3
PA
155 c_s.method ();
156 v_s.method ();
157 cv_s.method ();
858be34c
PA
158 s.inline_method ();
159 S::static_method ();
160 S::static_inline_method ();
161
162 s2.method ();
163 s2.inline_method ();
164 S2<int>::static_method ();
165 S2<int>::static_inline_method ();
166#endif
167 }
168
169 return 0;
170}