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

Only check fixed underlying type in declarations, not in references #531

Merged
merged 3 commits into from
Oct 27, 2023
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
4 changes: 3 additions & 1 deletion src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,9 @@ fn enumSpec(p: *Parser) Error!Type {
// check if this is a reference to a previous type
const interned_name = try p.comp.intern(p.tokSlice(ident));
if (try p.syms.findTag(p, interned_name, .keyword_enum, ident, p.tok_ids[p.tok_i])) |prev| {
try p.checkEnumFixedTy(fixed_ty, ident, prev);
// only check fixed underlying type in forward declarations and not in references.
if (p.tok_ids[p.tok_i] == .semicolon)
try p.checkEnumFixedTy(fixed_ty, ident, prev);
return prev.ty;
} else {
// this is a forward declaration, create a new enum Type.
Expand Down
4 changes: 4 additions & 0 deletions test/cases/enum fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ enum E6: char {
a = 0u,
};

enum E e;
enum E: int;
void fn(enum E);

#define EXPECTED_ERRORS "enum fixed.c:2:7: warning: enumeration types with a fixed underlying type are a Clang extension [-Wfixed-enum-extension]" \
"enum fixed.c:4:6: error: enumeration previously declared with fixed underlying type" \
"enum fixed.c:2:6: note: previous definition is here" \
Expand Down
Loading