1 /* This testcase is part of GDB, the GNU debugger.
2 
3    Copyright 2011-2020 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 
18    Contributed by Red Hat, originally written by Keith Seitz.  */
19 
20 #include <stdlib.h>
21 
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;
33 
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);
38 
39 // For c++/24367 testing
40 typedef struct incomplete_struct incomplete_struct;
41 typedef struct _incomplete_struct another_incomplete_struct;
test_incomplete(incomplete_struct * p)42 int test_incomplete (incomplete_struct *p) { return 0; } // test_incomplete(incomplete_struct*)
test_incomplete(another_incomplete_struct * p)43 int test_incomplete (another_incomplete_struct *p) { return 1; } // test_incomplete(another_incomplete_struct*)
test_incomplete(int * p)44 int test_incomplete (int *p) { return -1; } // test_incomplete(int*)
45 
46 namespace A
47 {
48   class foo
49   {
50   public:
foo(void)51     foo (void) { }
foo(my_other_type a)52     foo (my_other_type a) { } // A::FOO::foo(my_other_type)
foo(my_other_type_2 a)53     foo (my_other_type_2 a) { } // A::FOO::foo(my_other_type_2)
foo(my_other_type_2 a,const my_other_type b)54     foo (my_other_type_2 a, const my_other_type b) { } // A::FOO::foo(my_other_type_2, const my_other_type)
foo(fptr3)55     foo (fptr3) { } // A::FOO::foo(fptr3)
foo(fptr1 * a)56     foo (fptr1* a) { } // A::FOO::foo(fptr1*)
foo(CORE_ADDR (*)[10])57     foo (CORE_ADDR (*) [10]) { } // A::FOO::foo(CORE_ADDR (*) [10])
foo(aenum a,astruct const & b,aunion const *** c)58     foo (aenum a, astruct const& b, aunion const*** c) { } // A::FOO::foo(aenum, astruct const&, aunion const***)
59 
test(my_other_type a)60     void test (my_other_type a) { } // A::FOO::test(my_other_type)
test(my_other_type_2 a)61     void test (my_other_type_2 a) { } // A::FOO::test(my_other_type_2)
test(my_other_type_2 a,const my_other_type b)62     void test (my_other_type_2 a, const my_other_type b) { } // A::FOO::test(my_other_type_2, const my_other_type)
test(fptr3 a)63     void test (fptr3 a) { } // A::FOO::test(fptr3)
test(fptr1 * a)64     void test (fptr1* a) { } // A::FOO::test(fptr1*)
test(CORE_ADDR (*)[10])65     void test (CORE_ADDR (*) [10]) { } // A::FOO::test(CORE_ADDR (*) [10])
test(aenum a,astruct const & b,aunion const *** c)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 
72 namespace B
73 {
74   void
test(my_other_type foo)75   test (my_other_type foo) { } // B::test(my_other_type)
76 
77   void
test(aenum a,astruct const & b,aunion const *** c)78   test (aenum a, astruct const& b, aunion const*** c) { } // B::test(aenum, astruct const&, aunion const***)
79 
80   template <typename T1, typename T2>
test(T1 a,T2 b)81   void test (T1 a, T2 b) { } // B::test (T1, T2)
82 
83   template <>
test(my_other_type foo,my_other_type_2)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 
87 namespace 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 
103 typedef a::b::BAR _BAR_;
104 
105 template <typename T1, typename T2>
test(T1 a,T2 b)106 void test (T1 a, T2 b) {} // test (T1, T2)
107 
108 template <>
test(my_other_type foo,my_other_type_2)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)
110 
111 void
test(my_other_type foo)112 test (my_other_type foo) { } // test(my_other_type)
113 
114 void
test(_BAR_ & b)115 test (_BAR_ &b) { } // test(_BAR_&)
116 
117 void
test(aenum a,astruct const & b,aunion const *** c)118 test (aenum a, astruct const& b, aunion const*** c) { } // test(aenum, astruct const&, aunion const***)
119 
120 int
main(void)121 main (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 
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));
163   return 0;
164 }
165