[clang] [C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue May 6 13:08:18 PDT 2025
AaronBallman wrote:
> @AaronBallman If you try to compile the following c program after this patch
>
> ```
> void free ();
> typedef enum {REG_EESCAPE} reg_errcode_t;
> typedef struct {int *stack;} compile_stack_type;
> reg_errcode_t byte_regex_compile () {
> compile_stack_type compile_stack;
> return (free (compile_stack.stack), REG_EESCAPE);
> }
> ```
>
> cmd: `clang -Wimplicit-int-enum-cast -c pre.i`
>
> It will give an incorrect diagnostic:
>
> ```
> pre.i:6:37: warning: implicit conversion from 'int' to enumeration type 'reg_errcode_t' is invalid in C++ [-Wimplicit-int-enum-cast]
> 6 | return (free (compile_stack.stack), REG_EESCAPE);
> | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
> 1 warning generated.
> ```
https://github.com/llvm/llvm-project/pull/138752 should address this issue, thank you for bringing it up!
https://github.com/llvm/llvm-project/pull/137658
More information about the cfe-commits
mailing list