llvm / llvm/llvm-project

[clang] [diagnostics] Wrong -Wimplicit-int-enum-cast warning

Open
#185,400 2 comments 0 reactions 1 assignee Claimed by @flash1729 View on GitHub
clang:diagnostics confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Compile this C code snippet with trunk Clang using -Wc++-compat

```c++
void free(void *p);

typedef enum
{
REG_EBRACE,
REG_BADBR,
} reg_errcode_t;

# define FREE_STACK_RETURN(value) \
return (free (compile_stack.stack), value)

reg_errcode_t
regex_compile (void *bufp)
{
struct { int *stack; int b;} compile_stack;
FREE_STACK_RETURN (bufp ? REG_EBRACE : REG_BADBR);
}
```

Clang will complain

```
:16:22: warning: implicit conversion from 'int' to enumeration type 'reg_errcode_t' is invalid in C++ [-Wimplicit-int-enum-cast]
16 | FREE_STACK_RETURN (bufp ? REG_EBRACE : REG_BADBR);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:10:39: note: expanded from macro 'FREE_STACK_RETURN'
10 | return (free (compile_stack.stack), value)
| ~ ^~~~~
```

But this warning doesn't make sense. As far as I can tell, no int is involved. No implicit conversion from int should be happening. GCC doesn't generate any similar warning:
https://godbolt.org/z/WdMxbYjTz

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.