History

Fix type compatiblity of enums and ints

an enum must be compatible with one or more integer type, so adjust the test accordingly. That means the following redeclarations should work: enum e6 { E1 = -1, E0 }; void f3(enum e6); void f3(int); // should work as int and e6 are compatible while the following should not: void f4(enum e6 e); void f4(unsigned e); // should error as unsigned and e6 are incompatible

Michael Matz committed 6 years ago

Commit 9eef3391 parent 068d5b33 files · +41 −29Browse files

Unified · Split

3 files
  1. tccgen.c +3 −1
  2. tests/tests2/60_errors_and_warnings.c +7 −0
  3. tests/tests2/60_errors_and_warnings.expect +31 −28
tccgen.c+3−1
@@ -3009,7 +3009,9 @@ static int compare_types(CType *type1, CType *type2, int unqualified) · 3008 unmodified lines
3009 return (type1->ref == type2->ref);3009 return (type1->ref == type2->ref);
3010 } else if (bt1 == VT_FUNC) {3010 } else if (bt1 == VT_FUNC) {
3011 return is_compatible_func(type1, type2);3011 return is_compatible_func(type1, type2);
3012 } else if (IS_ENUM(type1->t) || IS_ENUM(type2->t)) {3012 } else if (IS_ENUM(type1->t) && IS_ENUM(type2->t)) {
3013 /* If both are enums then they must be the same, if only one is then
3014 t1 and t2 must be equal, which was checked above already. */
3013 return type1->ref == type2->ref;3015 return type1->ref == type2->ref;
3014 } else {3016 } else {
3015 return 1;3017 return 1;
tests/tests2/60_errors_and_warnings.c+7−0
@@ -118,6 +118,13 @@ enum e5; · 117 unmodified lines
118void f3(enum e4 e);118void f3(enum e4 e);
119void f3(enum e5 e);119void f3(enum e5 e);
120 120
121#elif defined test_enum_compat_2
122enum e6 { E1 = -1, E0 };
123void f3(enum e6);
124void f3(int); // should work as int and e6 are compatible
125void f4(enum e6 e);
126void f4(unsigned e); // should error as unsigned and e6 are incompatible
127
121#elif defined test_ptr_to_str128#elif defined test_ptr_to_str
122void f() { _Generic((int const *[]){0}, int:0); }129void f() { _Generic((int const *[]){0}, int:0); }
123#elif defined test_fnptr_to_str130#elif defined test_fnptr_to_str
tests/tests2/60_errors_and_warnings.expect+31−28
@@ -46,73 +46,76 @@ · 45 unmodified lines
46[test_enum_compat]46[test_enum_compat]
4760_errors_and_warnings.c:119: error: incompatible types for redefinition of 'f3'4760_errors_and_warnings.c:119: error: incompatible types for redefinition of 'f3'
48 48
49[test_enum_compat_2]
5060_errors_and_warnings.c:126: error: incompatible types for redefinition of 'f4'
51
49[test_ptr_to_str]52[test_ptr_to_str]
5060_errors_and_warnings.c:122: error: type 'const int **' does not match any association5360_errors_and_warnings.c:129: error: type 'const int **' does not match any association
51 54
52[test_fnptr_to_str]55[test_fnptr_to_str]
5360_errors_and_warnings.c:124: error: type 'int (*(*)(float, char))(double, int)' does not match any association5660_errors_and_warnings.c:131: error: type 'int (*(*)(float, char))(double, int)' does not match any association
54 57
55[test_array_to_str]58[test_array_to_str]
5660_errors_and_warnings.c:126: error: type 'int (*)[3]' does not match any association5960_errors_and_warnings.c:133: error: type 'int (*)[3]' does not match any association
57 60
58[test_duplicate_def_1]61[test_duplicate_def_1]
5960_errors_and_warnings.c:128: error: redefinition of 'L'6260_errors_and_warnings.c:135: error: redefinition of 'L'
60 63
61[test_duplicate_def_2]64[test_duplicate_def_2]
6260_errors_and_warnings.c:131: error: redeclaration of 'L'6560_errors_and_warnings.c:138: error: redeclaration of 'L'
63 66
64[test_abstract_decls]67[test_abstract_decls]
6560_errors_and_warnings.c:141: error: identifier expected6860_errors_and_warnings.c:148: error: identifier expected
66 69
67[test_invalid_1]70[test_invalid_1]
6860_errors_and_warnings.c:146: error: identifier expected7160_errors_and_warnings.c:153: error: identifier expected
69 72
70[test_invalid_2]73[test_invalid_2]
7160_errors_and_warnings.c:149: error: ';' expected (got "{")7460_errors_and_warnings.c:156: error: ';' expected (got "{")
72 75
73[test_invalid_3]76[test_invalid_3]
7460_errors_and_warnings.c:153: error: ',' expected (got "a")7760_errors_and_warnings.c:160: error: ',' expected (got "a")
75 78
76[test_invalid_4]79[test_invalid_4]
7760_errors_and_warnings.c:157: error: division by zero in constant8060_errors_and_warnings.c:164: error: division by zero in constant
78 81
79[test_conflicting_types]82[test_conflicting_types]
8060_errors_and_warnings.c:163: error: incompatible types for redefinition of 'i'8360_errors_and_warnings.c:170: error: incompatible types for redefinition of 'i'
81 84
82[test_nested_types]85[test_nested_types]
8360_errors_and_warnings.c:170: error: struct/union/enum already defined8660_errors_and_warnings.c:177: error: struct/union/enum already defined
84 87
85[test_vla_1]88[test_vla_1]
8660_errors_and_warnings.c:177: error: need explicit inner array size in VLAs8960_errors_and_warnings.c:184: error: need explicit inner array size in VLAs
87 90
88[test_invalid_alignas]91[test_invalid_alignas]
8960_errors_and_warnings.c:181: error: identifier expected9260_errors_and_warnings.c:188: error: identifier expected
90 93
91[test_static_assert]94[test_static_assert]
9260_errors_and_warnings.c:187: error: ONE is not 19560_errors_and_warnings.c:194: error: ONE is not 1
93 96
94[test_static_assert_2]97[test_static_assert_2]
9560_errors_and_warnings.c:191: error: 0 is 09860_errors_and_warnings.c:198: error: 0 is 0
96 99
97[test_static_assert_c2x]100[test_static_assert_c2x]
9860_errors_and_warnings.c:195: error: _Static_assert fail10160_errors_and_warnings.c:202: error: _Static_assert fail
99 102
100[test_void_array]103[test_void_array]
10160_errors_and_warnings.c:198: error: declaration of an array of incomplete type elements10460_errors_and_warnings.c:205: error: declaration of an array of incomplete type elements
102 105
103[test_incomplete_enum_array]106[test_incomplete_enum_array]
10460_errors_and_warnings.c:201: error: declaration of an array of incomplete type elements10760_errors_and_warnings.c:208: error: declaration of an array of incomplete type elements
105 108
106[test_incomplete_struct_array]109[test_incomplete_struct_array]
10760_errors_and_warnings.c:204: error: declaration of an array of incomplete type elements11060_errors_and_warnings.c:211: error: declaration of an array of incomplete type elements
108 111
109[test_const_fun_array]112[test_const_fun_array]
11060_errors_and_warnings.c:208: error: declaration of an array of functions11360_errors_and_warnings.c:215: error: declaration of an array of functions
111 114
112[test_incomplete_array_array]115[test_incomplete_array_array]
113 116
114[test_extern_array]117[test_extern_array]
11560_errors_and_warnings.c:224: error: incompatible types for redefinition of 'x'11860_errors_and_warnings.c:231: error: incompatible types for redefinition of 'x'
116 119
117[test_func_1]120[test_func_1]
118hello: a = 123121hello: a = 123
@@ -121,17 +124,17 @@ hello: a = 123 · 2 unmodified lines
121hello: a = 123124hello: a = 123
122 125
123[test_func_3]126[test_func_3]
12460_errors_and_warnings.c:254: warning: static storage ignored for redefinition of 'hello'12760_errors_and_warnings.c:261: warning: static storage ignored for redefinition of 'hello'
125hello: a = 123128hello: a = 123
126 129
127[test_func_4]130[test_func_4]
128hello: a = 123131hello: a = 123
129 132
130[test_func_5]133[test_func_5]
13160_errors_and_warnings.c:254: error: incompatible types for redefinition of 'hello'13460_errors_and_warnings.c:261: error: incompatible types for redefinition of 'hello'
132 135
133[test_func_6]136[test_func_6]
13460_errors_and_warnings.c:242: error: function without file scope cannot be static13760_errors_and_warnings.c:249: error: function without file scope cannot be static
135 138
136[test_var_1]139[test_var_1]
137main : 1 ; 1140main : 1 ; 1
@@ -144,12 +147,12 @@ main : 2 ; 2 · 6 unmodified lines
144bar : 3 ; 3147bar : 3 ; 3
145 148
146[test_var_3]149[test_var_3]
14760_errors_and_warnings.c:286: error: incompatible types for redefinition of 'xxx'15060_errors_and_warnings.c:293: error: incompatible types for redefinition of 'xxx'
148 151
149[test_var_4]152[test_var_4]
150 153
151[test_long_double_type_for_win32]154[test_long_double_type_for_win32]
15260_errors_and_warnings.c:317: warning: assignment from incompatible pointer type15560_errors_and_warnings.c:324: warning: assignment from incompatible pointer type
153 156
154[test_stray_backslash]157[test_stray_backslash]
15560_errors_and_warnings.c:323: error: stray '\' in program15860_errors_and_warnings.c:330: error: stray '\' in program

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t