aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-08-21 02:27:11 +0100
committerVeikka Tuominen <git@vexu.eu>2023-08-21 11:47:31 +0300
commit283afb50b56fb8a2c288d2452bdf6e595a1bbb06 (patch)
tree074cfa8a07a8763d455289a20fc0b08e1b0395be /test
parent411462e1cdac518ccb67a8dd7aa5ef93332f8d19 (diff)
downloadzig-283afb50b56fb8a2c288d2452bdf6e595a1bbb06.tar.gz
zig-283afb50b56fb8a2c288d2452bdf6e595a1bbb06.zip
AstGen: disallow '-0' integer literal
The intent here is ambiguous: this resolves to the comptime_int '0', but it's likely the user meant to use a floating-point literal. Resolves: #16890
Diffstat (limited to 'test')
-rw-r--r--test/behavior/bitcast.zig2
-rw-r--r--test/cases/compile_errors/negative_zero_literal.zig11
2 files changed, 11 insertions, 2 deletions
diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig
index e47d9f2f0b..4fb937fa2c 100644
--- a/test/behavior/bitcast.zig
+++ b/test/behavior/bitcast.zig
@@ -63,8 +63,6 @@ fn testBitCast(comptime N: usize) !void {
try expect(conv_uN(N, 0) == 0);
try expect(conv_iN(N, 0) == 0);
- try expect(conv_iN(N, -0) == 0);
-
if (N > 24) {
try expect(conv_uN(N, 0xf23456) == 0xf23456);
}
diff --git a/test/cases/compile_errors/negative_zero_literal.zig b/test/cases/compile_errors/negative_zero_literal.zig
new file mode 100644
index 0000000000..4ae9931e8d
--- /dev/null
+++ b/test/cases/compile_errors/negative_zero_literal.zig
@@ -0,0 +1,11 @@
+export fn foo() void {
+ _ = -0;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:10: error: integer literal '-0' is ambiguous
+// :2:10: note: use '0' for an integer zero
+// :2:10: note: use '-0.0' for a floating-point signed zero