| author | |
| committer | |
| log | fa6546ba743fe145ad65d9ca76fe9e9e01d05056 |
| tree | 947d63ce806687cef2ca59b3af34e3dacf5a6147 |
| parent | fc8791c133c14fe969b9056d8f0e337094ce1461 |
3 files changed, 14 insertions(+), 2 deletions(-)
src/translate_c.zig+2-1| ... | ... | @@ -1931,7 +1931,8 @@ fn finishBoolExpr( |
| 1931 | 1931 | }, |
| 1932 | 1932 | .Enum => { |
| 1933 | 1933 | // node != 0 |
| 1934 | return Tag.not_equal.create(c.arena, .{ .lhs = node, .rhs = Tag.zero_literal.init() }); | |
| 1934 | const int_val = try Tag.enum_to_int.create(c.arena, node); | |
| 1935 | return Tag.not_equal.create(c.arena, .{ .lhs = int_val, .rhs = Tag.zero_literal.init() }); | |
| 1935 | 1936 | }, |
| 1936 | 1937 | .Elaborated => { |
| 1937 | 1938 | const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty); |
test/run_translated_c.zig+11| ... | ... | @@ -1508,4 +1508,15 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 1508 | 1508 | \\ return 0; |
| 1509 | 1509 | \\} |
| 1510 | 1510 | , ""); |
| 1511 | ||
| 1512 | cases.add("enum used as boolean expression", | |
| 1513 | \\#include <stdlib.h> | |
| 1514 | \\enum FOO {BAR, BAZ}; | |
| 1515 | \\int main(void) { | |
| 1516 | \\ enum FOO x = BAR; | |
| 1517 | \\ if (x) abort(); | |
| 1518 | \\ if (!BAZ) abort(); | |
| 1519 | \\ return 0; | |
| 1520 | \\} | |
| 1521 | , ""); | |
| 1511 | 1522 | } |
test/translate_c.zig+1-1| ... | ... | @@ -2668,7 +2668,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2668 | 2668 | \\ if (a != 0) return 0; |
| 2669 | 2669 | \\ if (b != 0) return 1; |
| 2670 | 2670 | \\ if (c != null) return 2; |
| 2671 | \\ if (d != 0) return 3; | |
| 2671 | \\ if (@enumToInt(d) != 0) return 3; | |
| 2672 | 2672 | \\ return 4; |
| 2673 | 2673 | \\} |
| 2674 | 2674 | }); |