Is there a way to get Clang or GCC to warn when assigning a plain integer to a variable of enum type? This question refers to C, not C++.
Example:
typedef enum foo_e { A=1, B=2 } foo_t;
foo_t fun() {
foo_t x = A; // this is fine
foo_t y = 2; // should trigger a warning
int z = B; // this is fine
return 1; // should trigger a warning, as the return type is foo_t
}
The "classic" Intel compiler issues a warning for these cases: warning #188, "enumerated type mixed with another type". This revealed several real bugs in our code. However, this being an open-source project run by volunteers, we do not have the possibility to test with this non-free compiler on a regular basis, and cannot integrate it into CI pipeline. Having seen the value of these checks, I am wondering if there is a way to get them with Clang or GCC.