# translate-c: better handling of int \-\> enum casts · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d4d21dd46d69961300cc796abdebe352dfe6eae8)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d4d21dd46d69961300cc796abdebe352dfe6eae8

Requested commit: d4d21dd46d69961300cc796abdebe352dfe6eae8

Commit: d4d21dd46d69961300cc796abdebe352dfe6eae8

Tree: aa0e3483f5536d0d8b74894c78e373b045ca3f1b

Author: Evan Haas

Committer: Andrew Kelley

## Message

```
translate-c: better handling of int -> enum casts

In std.meta.cast when casting to an enum type from an integer type, first
do a C-style cast from the source value to the tag type of the enum.
This ensures that we don't get an error due to the source value not being
representable by the enum.

In transCCast() use std.meta.cast instead of directly emitting the cast
operation since the enum's underlying type may not be known at translation
time due to an MSVC bug, see https://github.com/ziglang/zig/issues/8003

Fixes #6011

```

## Parents

- [ccdf55310bee2dcf86b718d26a56933dc1a03443](https://git.cafe/gitcafe/zig/commit/ccdf55310bee2dcf86b718d26a56933dc1a03443?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d4d21dd46d69961300cc796abdebe352dfe6eae8?format=markdown)
