Skip to content

Commit

Permalink
Parser: Add support for missing '=' in designated init
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Jan 11, 2025
1 parent 8a4e7d1 commit b2d9b1f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/aro/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub const Options = struct {
@"address-of-packed-member": Kind = .default,
nonnull: Kind = .default,
@"atomic-access": Kind = .default,
@"gnu-designator": Kind = .default,
};

const Diagnostics = @This();
Expand Down
5 changes: 5 additions & 0 deletions src/aro/Diagnostics/messages.def
Original file line number Diff line number Diff line change
Expand Up @@ -2628,3 +2628,8 @@ attribute_param_out_of_bounds
alloc_align_required_int_param
.msg = "'alloc_align' attribute argument may only refer to a function parameter of integer type"
.kind = .@"error"

gnu_missing_eq_designator
.msg = "use of GNU 'missing =' extension in designator"
.kind = .warning
.opt = W("gnu-designator")
6 changes: 5 additions & 1 deletion src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,11 @@ fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType) Error!bool {
if (designation) index_hint = null;
defer index_hint = cur_index_hint orelse null;

if (designation) _ = try p.expectToken(.equal);
if (designation) {
if (p.eatToken(.equal) == null) {
try p.err(.gnu_missing_eq_designator);
}
}

if (!designation and cur_qt.hasAttribute(p.comp, .designated_init)) {
try p.err(.designated_init_needed);
Expand Down
6 changes: 6 additions & 0 deletions test/cases/gnu designated init extension.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int x[] = {[1] 2, [3] 4};
_Static_assert(sizeof(x) == sizeof(int[4]), "Incorrect array size");

#define EXPECTED_ERRORS "gnu designated init extension.c:1:16: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator]" \
"gnu designated init extension.c:1:23: warning: use of GNU 'missing =' extension in designator [-Wgnu-designator]" \

0 comments on commit b2d9b1f

Please sign in to comment.