Skip to content

Commit

Permalink
Parser: handle arrays of string literal initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Jan 8, 2025
1 parent 58a9330 commit 36678b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4186,12 +4186,12 @@ fn coerceArrayInitExtra(p: *Parser, item: *Result, tok: TokenIndex, target: Qual
const target_elem = target_array_ty.elem;
const item_elem = maybe_item_array_ty.?.elem;

const target_int = target_elem.get(p.comp, .int);
const item_int = item_elem.get(p.comp, .int);
const target_int = target_elem.get(p.comp, .int) orelse .int; // not int; string compat checks below will fail by design
const item_int = item_elem.get(p.comp, .int) orelse .int; // not int; string compat checks below will fail by design

const compatible = target_elem.eql(item_elem, p.comp) or
(is_str_lit and item_int.? == .char and (target_int.? == .uchar or target_int.? == .schar)) or
(is_str_lit and item_int.? == .uchar and (target_int.? == .uchar or target_int.? == .schar or target_int.? == .char));
(is_str_lit and item_int == .char and (target_int == .uchar or target_int == .schar)) or
(is_str_lit and item_int == .uchar and (target_int == .uchar or target_int == .schar or target_int == .char));
if (!compatible) {
if (!report_err) return false;
const e_msg = " with array of type ";
Expand Down
4 changes: 4 additions & 0 deletions test/cases/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const char *s1 = (const char *)"hello";
const char *s2 = "hello" + 1;
const char *s3 = "hello" - 1;

char * const string_array[] = {
"string",
};

#define EXPECTED_ERRORS "strings.c:2:29: error: escape sequence out of range" \
"strings.c:4:19: error: invalid universal character" \
"strings.c:5:19: error: character 'b' cannot be specified by a universal character name" \
Expand Down

0 comments on commit 36678b5

Please sign in to comment.