Skip to content

Commit

Permalink
Merge pull request #584 from ehaas/fn-eql
Browse files Browse the repository at this point in the history
Function type comparison tweaks
  • Loading branch information
Vexu authored Nov 27, 2023
2 parents 86f8f05 + efed229 commit 349d32a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 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 All @@ -114,6 +115,7 @@ pub const Func = struct {
}
return true;
}
return false;
}
if ((a_spec == .func) != (b_spec == .func)) return false;
// TODO validate this
Expand Down
6 changes: 6 additions & 0 deletions test/cases/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ int (*return_array_ptr(void))[2] {
return &ARRAY;
}

void no_params(void);
void no_params(int x){}

#define EXPECTED_ERRORS "functions.c:10:12: error: parameter named 'quux' is missing" \
"functions.c:20:14: error: illegal initializer (only variables can be initialized)" \
"functions.c:18:2: warning: non-void function 'foooo' does not return a value [-Wreturn-type]" \
Expand All @@ -85,3 +88,6 @@ int (*return_array_ptr(void))[2] {
"functions.c:50:3: error: parameter has incomplete type 'union Union'" \
"functions.c:53:30: error: parameter has incomplete type 'enum E'" \
"functions.c:55:9: error: parameter has incomplete type 'enum EE'" \
"functions.c:79:6: error: redefinition of 'no_params' with a different type" \
"functions.c:78:6: note: previous definition is here" \

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 349d32a

Please sign in to comment.