Skip to content

Commit

Permalink
Type: old & new style function types can be equal if there are no par…
Browse files Browse the repository at this point in the history
…ameters
  • Loading branch information
ehaas committed Nov 27, 2023
1 parent 4306589 commit efed229
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub const Func = struct {
fn eql(a: *const Func, b: *const Func, a_spec: Specifier, b_spec: Specifier, comp: *const Compilation) bool {
// return type cannot have qualifiers
if (!a.return_type.eql(b.return_type, comp, false)) return false;
if (a.params.len == 0 and b.params.len == 0) return true;

if (a.params.len != b.params.len) {
if (a_spec == .old_style_func or b_spec == .old_style_func) {
Expand Down
6 changes: 6 additions & 0 deletions test/cases/redefinitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ int f4(int);
int f5(int (*)(), double (*)[3]);
int f5(int (*)(char), double (*)[]); // not compatible since char undergoes default argument promotion

void f6();
void f6(void) {}

void f7(void);
void f7() {}

#define EXPECTED_ERRORS "redefinitions.c:4:5: error: redefinition of 'foo' as different kind of symbol" \
"redefinitions.c:1:5: note: previous definition is here" \
"redefinitions.c:5:5: error: redefinition of 'foo' as different kind of symbol" \
Expand Down

0 comments on commit efed229

Please sign in to comment.