diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 73efae2037..22d63568bf 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -1229,6 +1229,10 @@ void tokenize(Buf *buf, Tokenization *out) { break; } if (is_exponent_signifier(c, t.radix)) { + if (t.is_trailing_underscore) { + invalid_char_error(&t, c); + break; + } if (t.radix != 16 && t.radix != 10) { invalid_char_error(&t, c); } @@ -1296,6 +1300,10 @@ void tokenize(Buf *buf, Tokenization *out) { break; } if (is_exponent_signifier(c, t.radix)) { + if (t.is_trailing_underscore) { + invalid_char_error(&t, c); + break; + } t.state = TokenizeStateFloatExponentUnsigned; t.radix = 10; // exponent is always base 10 break; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 83fe1def62..2b40fec106 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -485,6 +485,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:2:23: error: invalid character: '_'", }); + cases.add("invalid underscore placement in float literal - 14", + \\fn main() void { + \\ var bad: f128 = 0x0.0_p1; + \\}) + , &[_][]const u8{ + "tmp.zig:2:27: error: invalid character: 'p'", + }); + cases.add("var args without c calling conv", \\fn foo(args: ...) void {} \\comptime {