1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2011-2019 Free Software Foundation, Inc.
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.
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.
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/>.
18 Contributed by Red Hat, originally written by Keith Seitz. */
22 typedef const char* const* my_type
;
23 typedef int my_type_2
;
24 typedef my_type my_other_type
;
25 typedef my_type_2 my_other_type_2
;
26 typedef unsigned long CORE_ADDR
;
27 typedef enum {E_A
, E_B
, E_C
} anon_enum
;
28 typedef struct {int a
; char b
;} anon_struct
;
29 typedef union {int a
; char b
;} anon_union
;
30 typedef anon_enum aenum
;
31 typedef anon_struct astruct
;
32 typedef anon_union aunion
;
34 typedef void (*fptr1
) (my_other_type
);
35 typedef void (*fptr2
) (fptr1
, my_other_type_2
);
36 typedef void (*fptr3
) (fptr2
, my_other_type
);
37 typedef void (*fptr4
) (anon_enum a
, anon_struct
const& b
, anon_union
const*** c
);
39 // For c++/24367 testing
40 typedef struct incomplete_struct incomplete_struct
;
41 typedef struct _incomplete_struct another_incomplete_struct
;
42 int test_incomplete (incomplete_struct
*p
) { return 0; } // test_incomplete(incomplete_struct*)
43 int test_incomplete (another_incomplete_struct
*p
) { return 1; } // test_incomplete(another_incomplete_struct*)
44 int test_incomplete (int *p
) { return -1; } // test_incomplete(int*)
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***)
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***)
75 test (my_other_type foo
) { } // B::test(my_other_type)
78 test (aenum a
, astruct
const& b
, aunion
const*** c
) { } // B::test(aenum, astruct const&, aunion const***)
80 template <typename T1
, typename T2
>
81 void test (T1 a
, T2 b
) { } // B::test (T1, T2)
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)
99 typedef c::d::bar BAR
;
103 typedef a::b::BAR _BAR_
;
105 template <typename T1
, typename T2
>
106 void test (T1 a
, T2 b
) {} // test (T1, T2)
109 void test (my_other_type foo
, my_other_type_2
) { } // test<my_other_type, my_other_type_2>(my_other_type, my_other_type_2)
112 test (my_other_type foo
) { } // test(my_other_type)
115 test (_BAR_
&b
) { } // test(_BAR_&)
118 test (aenum a
, astruct
const& b
, aunion
const*** c
) { } // test(aenum, astruct const&, aunion const***)
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
;
131 my_foo
.test (static_cast<my_other_type
> (NULL
));
133 my_foo
.test (0, static_cast<my_type
> (NULL
));
134 my_foo
.test (static_cast<fptr3
> (NULL
));
136 my_foo
.test (static_cast<CORE_ADDR (*) [10]> (0));
137 my_foo
.test (E_A
, as
, auppp
);
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
);
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
);
147 A::foo
a (static_cast<my_other_type
> (NULL
));
149 A::foo
c (0, static_cast<my_other_type
> (NULL
));
150 A::foo
d (static_cast<fptr3
> (NULL
));
152 A::foo
f (static_cast<CORE_ADDR (*) [10]> (0));
153 A::foo
g (E_A
, as
, auppp
);
157 // Tests for c++/24367
159 incomplete_struct
*is
= nullptr;
160 another_incomplete_struct
*ais
= nullptr;
161 int result
= (test_incomplete (i
) + test_incomplete (is
)
162 + test_incomplete (ais
));