1 /* PR c/97882 - Segmentation Fault on improper redeclaration of function
2 { dg-do compile }
3 { dg-options "" } */
4
5 // Check pointer declaration incompatibiliies.
6
7 extern enum E e_u; // { dg-message "note: previous declaration of 'e_u' with type 'enum E'" "note" }
8 unsigned e_u; // { dg-error "conflicting types for 'e_u'; have 'unsigned int'" }
9
10
11 extern enum E *p; // { dg-message "note: previous declaration of 'p' with type 'enum E \\*'" "note" }
12 unsigned *p; // { dg-error "conflicting types for 'p'; have 'unsigned int \\*'" }
13
14 extern enum E **p2; // { dg-message "note: previous declaration of 'p2' with type 'enum E \\*\\*'" "note" }
15 unsigned **p2; // { dg-error "conflicting types for 'p2'; have 'unsigned int \\*\\*'" }
16
17 extern enum E ***p3; // { dg-message "note: previous declaration of 'p3' with type 'enum E \\*\\*\\*'" "note" }
18 unsigned ***p3; // { dg-error "conflicting types for 'p3'; have 'unsigned int \\*\\*\\*'" }
19
20 extern enum F *q; // { dg-message "note: previous declaration of 'q' with type 'enum F \\*'" "note" }
21 int *q; // { dg-error "conflicting types for 'q'; have 'int \\*'" }
22
23 extern enum E* r[]; // { dg-message "note: previous declaration of 'r' with type 'enum E \\*\\\[]'" "note" }
24 extern unsigned *r[1]; // { dg-error "conflicting types for 'r'; have 'unsigned int \\*\\\[1]'" }
25
26 extern enum E **r2[]; // { dg-message "note: previous declaration of 'r2' with type 'enum E \\*\\*\\\[]'" "note" }
27 extern unsigned **r2[2];// { dg-error "conflicting types for 'r2'; have 'unsigned int \\*\\*\\\[2]'" }
28
29
30 typedef enum E* EPAx[];
31 typedef unsigned* UPAx[];
32
33 extern EPAx* peax; // { dg-message "note: previous declaration of 'peax' with type 'enum E \\* \\(\\*\\)\\\[]'" "note" }
34 extern UPAx* peax; // { dg-error "conflicting types for 'peax'; have 'unsigned int \\* \\(\\*\\)\\\[]'" }
35
36
37 /* Check incompatibilities in the return type in a redeclaration
38 of a function without a prototye. */
39
40 /* Verify the following isn't rejected. */
41 void f_v ();
42 void f_v (void);
43
44 enum E fE_u (); // { dg-message "previous declaration of 'fE_u' with type 'enum E\\(\\)'" "note" }
45 unsigned fE_u (); // { dg-error "conflicting types for 'fE_u'; have 'unsigned int\\(\\)'" }
46
47 enum E* fpE_u (); // { dg-message "previous declaration of 'fpE_u' with type 'enum E \\*\\(\\)'" "note" }
48 unsigned* fpE_u (); // { dg-error "conflicting types for 'fpE_u'; have 'unsigned int \\*\\(\\)'" }
49
50 enum E** fppE_u (); // { dg-message "previous declaration of 'fppE_u' with type 'enum E \\*\\*\\(\\)'" "note" }
51 unsigned** fppE_u (); // { dg-error "conflicting types for 'fppE_u'; have 'unsigned int \\*\\*\\(\\)'" }
52
53 enum E** fppE_u (); // { dg-message "previous declaration of 'fppE_u' with type 'enum E \\*\\*\\(\\)'" "note" }
54 unsigned** fppE_u (); // { dg-error "conflicting types for 'fppE_u'; have 'unsigned int \\*\\*\\(\\)'" }
55
56 enum E gE_u (); // { dg-message "previous declaration of 'gE_u' with type 'enum E\\(\\)'" "note" }
57 unsigned gE_u () // { dg-error "conflicting types for 'gE_u'; have 'unsigned int\\(\\)'" }
58 { return 0; }
59
60 enum E** gppE_u (); // { dg-message "previous declaration of 'gppE_u' with type 'enum E \\*\\*\\(\\)'" "note" }
61 unsigned** gppE_u () // { dg-error "conflicting types for 'gppE_u'; have 'unsigned int \\*\\*\\(\\)'" }
62 { return 0; }
63
64 unsigned fu_E (); // { dg-message "previous declaration of 'fu_E' with type 'unsigned int\\(\\)'" "note" }
65 enum E fu_E (); // { dg-error "conflicting types for 'fu_E'; have 'enum E\\(\\)'" }
66
67 unsigned gu_E (); // { dg-message "previous declaration of 'gu_E' with type 'unsigned int\\(\\)'" "note" }
68 enum E gu_E () { } // { dg-error "conflicting types for 'gu_E'" }
69 // { dg-error "incomplete type" "return type" { target *-*-* } .-1 }
70
71 typedef enum E FE_ ();
72 typedef unsigned Fuv (void);
73
74 FE_* fpF_u (); // // { dg-message "previous declaration of 'fpF_u' with type 'enum E \\(\\*\\(\\)\\)\\(\\)'" "note" }
75 Fuv* fpF_u (); // { dg-error "conflicting types for 'fpF_u'; have 'unsigned int \\(\\*\\(\\)\\)\\(void\\)'" }
76
77
78 typedef void Fv_ ();
79 typedef void Fvv (void);
80
81 /* Verify the following isn't rejected. */
82 Fv_* f ();
83 Fvv* f ();
84
85
86 /* Check incompatibilities in argument types of a function redeclaration. */
87
88 void fvE_u (enum E); // { dg-message "note: previous declaration of 'fvE_u' with type 'void\\(enum E\\)'" "note" }
89 void fvE_u (unsigned); // { dg-error "conflicting types for 'fvE_u'; have 'void\\(unsigned int\\)'" }
90
91 void fviE_u (int, enum E); // { dg-message "note: previous declaration of 'fviE_u' with type 'void\\(int, *enum E\\)'" "note" }
92 void fviE_u (int, unsigned); // { dg-error "conflicting types for 'fviE_u'; have 'void\\(int, *unsigned int\\)'" }
93
94 void fvE_el (enum E, ...); // { dg-message "note: previous declaration of 'fvE_el' with type 'void\\(enum E, \\.\\.\\.\\)'" "note" }
95 void fvE_el (unsigned, ...); // { dg-error "conflicting types for 'fvE_el'; have 'void\\(unsigned int, \\.\\.\\.\\)'" }
96
97
98 /* Check incompatibilities in the return type in a redeclaration
99 of a nested function without a prototye. */
100
101 void f1 (void)
102 {
103 enum G f11 (); // { dg-message "note: previous declaration of 'f11' with type 'enum G\\(\\)'" "note" }
104 unsigned f11 () { } // { dg-error "conflicting types for 'f11'; have 'unsigned int\\(\\)'" }
105 }
106
107
108 void f2 (void)
109 {
110 const enum G f21 (); // { dg-message "note: previous declaration of 'f21' with type 'enum G\\(\\)'" "note" }
111 unsigned f21 () { } // { dg-error "conflicting types for 'f21'; have 'unsigned int\\(\\)'" }
112 }
113
114
115 void f3 (void)
116 {
117 enum G f31 (); // { dg-message "note: previous declaration of 'f31' with type 'enum G\\(\\)'" "note" }
118 const unsigned f31 () { } // { dg-error "conflicting types for 'f31'; have 'unsigned int\\(\\)'" }
119 }
120
121
122 void f4 (void)
123 {
124 auto enum G f31 (); // { dg-message "note: previous declaration of 'f31' with type 'enum G\\(\\)'" "note" }
125 const unsigned f31 () { } // { dg-error "conflicting types for 'f31'; have 'unsigned int\\(\\)'" }
126 }
127
128
129 void f5 (void)
130 {
131 enum G* f51 (); // { dg-message "note: previous declaration of 'f51' with type 'enum G \\*\\(\\)'" "note" }
132 int* f51 () { } // { dg-error "conflicting types for 'f51'; have 'int \\*\\(\\)'" }
133 }
134
135
136 void f6 (void)
137 {
138 enum G;
139 void f61 (enum G); // { dg-message "note: previous declaration of 'f61' with type 'void\\(enum G\\)'" "note" }
140 void f61 (unsigned) // { dg-error "conflicting types for 'f61'; have 'void\\(unsigned int\\)'" }
141 { }
142 }
143
144 // { dg-prune-output "nested function '\[^\n\r ]+' declared but never defined" }