[clang] [C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)

via cfe-commits cfe-commits at lists.llvm.org
Tue May 6 06:10:10 PDT 2025


asmok-g wrote:

@AaronBallman If you try to compile the following 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/137658


More information about the cfe-commits mailing list