Skip to content

Commit

Permalink
Parser: add warning for using UTF-8 char literal before C23
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Nov 7, 2023
1 parent a7f0cbd commit 1c9e023
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,12 @@ const messages = struct {
const kind = .warning;
const suppress_version = .c23;
};
pub const u8_char_lit = struct {
const msg = "UTF-8 character literal is a C23 extension";
const opt = "c23-extensions";
const kind = .warning;
const suppress_version = .c23;
};
};

list: std.ArrayListUnmanaged(Message) = .{},
Expand Down
1 change: 1 addition & 0 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7684,6 +7684,7 @@ fn charLiteral(p: *Parser) Error!Result {
.node = try p.addNode(.{ .tag = .char_literal, .ty = Type.int, .data = undefined }),
};
};
if (char_kind == .utf_8) try p.err(.u8_char_lit);
var val: u32 = 0;

const slice = char_kind.contentSlice(p.tokSlice(p.tok_i));
Expand Down
6 changes: 4 additions & 2 deletions test/cases/u8 character constant.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const unsigned char c = u8'A';
_Static_assert(c == 'A', "");

#pragma GCC diagnostic ignored "-Wc23-extensions"
_Static_assert(u8'\xff' == 0xFF, "");

const unsigned char c2 = u8'™';
Expand All @@ -12,7 +12,9 @@ const unsigned char c4 = u8'AA';
#error Character constant should be true in preprocessor
#endif

#define EXPECTED_ERRORS "u8 character constant.c:6:26: error: character too large for enclosing character literal type" \
#define EXPECTED_ERRORS \
"u8 character constant.c:1:25: warning: UTF-8 character literal is a C23 extension [-Wc23-extensions]" \
"u8 character constant.c:6:26: error: character too large for enclosing character literal type" \
"u8 character constant.c:7:26: error: character too large for enclosing character literal type" \
"u8 character constant.c:8:26: error: Unicode character literals may not contain multiple characters" \

2 changes: 1 addition & 1 deletion test/cases/wide character constants.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//aro-args -Wfour-char-constants
//aro-args -Wfour-char-constants -Wno-c23-extensions
/*
A multiline comment to test that the linenumber is correct.
Expand Down

0 comments on commit 1c9e023

Please sign in to comment.