Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / meth-typedefs.cc
CommitLineData
59cde39c
KS
1/* This testcase is part of GDB, the GNU debugger.
2
88b9d363 3 Copyright 2011-2022 Free Software Foundation, Inc.
59cde39c
KS
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
18 Contributed by Red Hat, originally written by Keith Seitz. */
19
20#include <stdlib.h>
21
22typedef const char* const* my_type;
23typedef int my_type_2;
24typedef my_type my_other_type;
25typedef my_type_2 my_other_type_2;
26typedef unsigned long CORE_ADDR;
27typedef enum {E_A, E_B, E_C} anon_enum;
28typedef struct {int a; char b;} anon_struct;
29typedef union {int a; char b;} anon_union;
30typedef anon_enum aenum;
31typedef anon_struct astruct;
32typedef anon_union aunion;
33
34typedef void (*fptr1) (my_other_type);
35typedef void (*fptr2) (fptr1, my_other_type_2);
36typedef void (*fptr3) (fptr2, my_other_type);
37typedef void (*fptr4) (anon_enum a, anon_struct const& b, anon_union const*** c);
38
725cbb63
KS
39// For c++/24367 testing
40typedef struct incomplete_struct incomplete_struct;
41typedef struct _incomplete_struct another_incomplete_struct;
42int test_incomplete (incomplete_struct *p) { return 0; } // test_incomplete(incomplete_struct*)
43int test_incomplete (another_incomplete_struct *p) { return 1; } // test_incomplete(another_incomplete_struct*)
44int test_incomplete (int *p) { return -1; } // test_incomplete(int*)
45
59cde39c
KS
46namespace A
47{
48 class foo
49 {
50 public:
51 foo (void) { }
52 foo (my_other_type a) { } // A::FOO::foo(my_other_type)
53 foo (my_other_type_2 a) { } // A::FOO::foo(my_other_type_2)
54 foo (my_other_type_2 a, const my_other_type b) { } // A::FOO::foo(my_other_type_2, const my_other_type)
55 foo (fptr3) { } // A::FOO::foo(fptr3)
56 foo (fptr1* a) { } // A::FOO::foo(fptr1*)
57 foo (CORE_ADDR (*) [10]) { } // A::FOO::foo(CORE_ADDR (*) [10])
58 foo (aenum a, astruct const& b, aunion const*** c) { } // A::FOO::foo(aenum, astruct const&, aunion const***)
59
60 void test (my_other_type a) { } // A::FOO::test(my_other_type)
61 void test (my_other_type_2 a) { } // A::FOO::test(my_other_type_2)
62 void test (my_other_type_2 a, const my_other_type b) { } // A::FOO::test(my_other_type_2, const my_other_type)
63 void test (fptr3 a) { } // A::FOO::test(fptr3)
64 void test (fptr1* a) { } // A::FOO::test(fptr1*)
65 void test (CORE_ADDR (*) [10]) { } // A::FOO::test(CORE_ADDR (*) [10])
66 void test (aenum a, astruct const& b, aunion const*** c) { }; // A::FOO::test(aenum, astruct const&, aunion const***)
67 };
68
69 typedef foo FOO;
70};
71
72namespace B
73{
74 void
75 test (my_other_type foo) { } // B::test(my_other_type)
76
77 void
78 test (aenum a, astruct const& b, aunion const*** c) { } // B::test(aenum, astruct const&, aunion const***)
79
80 template <typename T1, typename T2>
81 void test (T1 a, T2 b) { } // B::test (T1, T2)
82
83 template <>
84 void test (my_other_type foo, my_other_type_2) { } // B::test<my_other_type, my_other_type_2>(my_other_type, my_other_type_2)
85};
86
87namespace a
88{
89 namespace b
90 {
91 namespace c
92 {
93 namespace d
94 {
95 class bar { };
96 }
97 }
98
99 typedef c::d::bar BAR;
100 }
101}
102
103typedef a::b::BAR _BAR_;
104
105template <typename T1, typename T2>
106void test (T1 a, T2 b) {} // test (T1, T2)
107
108template <>
109void test (my_other_type foo, my_other_type_2) { } // test<my_other_type, my_other_type_2>(my_other_type, my_other_type_2)
110
111void
112test (my_other_type foo) { } // test(my_other_type)
113
114void
115test (_BAR_ &b) { } // test(_BAR_&)
116
117void
118test (aenum a, astruct const& b, aunion const*** c) { } // test(aenum, astruct const&, aunion const***)
119
120int
121main (void)
122{
123 A::FOO my_foo;
124 fptr1 fptr;
125 astruct as = { 0, 0 };
126 aunion const au = { 0 };
127 aunion const* aup = &au;
128 aunion const** aupp = &aup;
129 aunion const*** auppp = &aupp;
130
131 my_foo.test (static_cast<my_other_type> (NULL));
132 my_foo.test (0);
133 my_foo.test (0, static_cast<my_type> (NULL));
134 my_foo.test (static_cast<fptr3> (NULL));
135 my_foo.test (&fptr);
136 my_foo.test (static_cast<CORE_ADDR (*) [10]> (0));
137 my_foo.test (E_A, as, auppp);
138
139 B::test (static_cast<my_other_type> (NULL));
140 B::test (static_cast<my_other_type> (NULL), 0);
141 B::test (E_A, as, auppp);
142
143 test (static_cast<my_other_type> (NULL));
144 test<my_other_type, my_other_type_2> (static_cast<my_other_type> (NULL), 0);
145 test (E_A, as, auppp);
146
147 A::foo a (static_cast<my_other_type> (NULL));
148 A::foo b (0);
149 A::foo c (0, static_cast<my_other_type> (NULL));
150 A::foo d (static_cast<fptr3> (NULL));
151 A::foo e (&fptr);
152 A::foo f (static_cast<CORE_ADDR (*) [10]> (0));
153 A::foo g (E_A, as, auppp);
154
155 fptr4 f4;
156
725cbb63
KS
157 // Tests for c++/24367
158 int *i = nullptr;
159 incomplete_struct *is = nullptr;
160 another_incomplete_struct *ais = nullptr;
161 int result = (test_incomplete (i) + test_incomplete (is)
162 + test_incomplete (ais));
59cde39c
KS
163 return 0;
164}
This page took 1.231926 seconds and 4 git commands to generate.