authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-04 00:44:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-04 00:44:44-07:00
log52ebba6bdf5662353ce11a701a3361cc0616c01c
tree540214fd396068acba89acfa6f29c425a12a1ee4
parent10016e0368c382363e168e45fac2cca4bc64e38f

`@shlExact` fixups

* Add clarification in langref * move test case to behavior tests

3 files changed, 7 insertions(+), 6 deletions(-)

doc/langref.html.in+5
...@@ -9163,6 +9163,11 @@ test "@setRuntimeSafety" {...@@ -9163,6 +9163,11 @@ test "@setRuntimeSafety" {
9163 The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.9163 The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
9164 This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.9164 This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
9165 </p>9165 </p>
9166 <p>
9167 {#syntax#}comptime_int{#endsyntax#} is modeled as an integer with an infinite number of bits,
9168 meaning that in such case, {#syntax#}@shlExact{#endsyntax#} always produces a result and
9169 cannot produce a compile error.
9170 </p>
9166 {#see_also|@shrExact|@shlWithOverflow#}9171 {#see_also|@shrExact|@shlWithOverflow#}
9167 {#header_close#}9172 {#header_close#}
91689173
test/behavior/math.zig+2
...@@ -1314,6 +1314,8 @@ test "exact shift left" {...@@ -1314,6 +1314,8 @@ test "exact shift left" {
13141314
1315 try testShlExact(0b00110101);1315 try testShlExact(0b00110101);
1316 try comptime testShlExact(0b00110101);1316 try comptime testShlExact(0b00110101);
1317
1318 if (@shlExact(1, 1) != 2) @compileError("should be 2");
1317}1319}
1318fn testShlExact(x: u8) !void {1320fn testShlExact(x: u8) !void {
1319 const shifted = @shlExact(x, 2);1321 const shifted = @shlExact(x, 2);
test/cases/shl_exact_comptime_int_lhs.zig deleted-6
...@@ -1,6 +0,0 @@
1export fn entry() void {
2 if (@shlExact(1, 1) != 2) @compileError("should be 2");
3}
4
5// compile
6// output_mode=Obj