Skip to content

Commit

Permalink
Type: disallow type specifiers from combining with types specified by…
Browse files Browse the repository at this point in the history
… typedefed names

Closes #731
  • Loading branch information
ehaas committed Dec 30, 2024
1 parent 9897a3e commit aa2a868
Show file tree
Hide file tree
Showing 3 changed files with 22 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 @@ -1905,6 +1905,8 @@ pub const Builder = struct {
/// Try to combine type from typedef, returns true if successful.
pub fn combineTypedef(b: *Builder, p: *Parser, typedef_ty: Type, name_tok: TokenIndex) bool {
if (typedef_ty.is(.invalid)) return false;
if (b.specifier != .none) return false;

b.error_on_invalid = true;
defer b.error_on_invalid = false;

Expand Down
7 changes: 7 additions & 0 deletions test/cases/duplicate typedef.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
typedef long foo;
typedef long foo;
_Static_assert(__builtin_types_compatible_p(long, foo), "");

typedef foo bar;
typedef foo bar;
_Static_assert(__builtin_types_compatible_p(bar, foo), "");
13 changes: 13 additions & 0 deletions test/cases/typedef extra specifiers disallowed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
typedef long foo;
typedef unsigned foo bar;

typedef double baz;
typedef long baz;

#define EXPECTED_ERRORS "typedef extra specifiers disallowed.c:2:18: error: typedef redefinition with different types ('unsigned int' vs 'long')" \
"typedef extra specifiers disallowed.c:1:14: note: previous definition is here" \
"typedef extra specifiers disallowed.c:2:22: error: expected ';', found 'an identifier'" \
"typedef extra specifiers disallowed.c:2:22: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]" \
"typedef extra specifiers disallowed.c:5:14: error: typedef redefinition with different types ('long' vs 'double')" \
"typedef extra specifiers disallowed.c:4:16: note: previous definition is here" \

0 comments on commit aa2a868

Please sign in to comment.