Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type: disallow type specifiers from combining with types specified by typedefed names #808

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" \

Loading