-
Notifications
You must be signed in to change notification settings - Fork 13.3k
-Wenum-compare doesn't catch mismatched enum constant comparison in C mode #29217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This diagnostic is implemented by Here's what
vs. in C:
In C++, the enumeration constants take the type of their enumeration. That's http://eel.is/c++draft/dcl.enum#5 and is implemented here: https://github.com/llvm-mirror/clang/blob/2bce94da/lib/Sema/SemaDecl.cpp#L16675-L16679 In C, though, enumeration constants have type The Clang diagnostic for implicit conversion between Enum types has explicit logic (added in llvm-mirror/clang@5a5b38f4a) to see "through" The solution here is probably to factor that logic out of |
…C mode Factored logic from `CheckImplicitConversion` into new methods `Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in `checkEnumArithmeticConversions`. Fix llvm#29217
…C mode Factored logic from `CheckImplicitConversion` into new methods `Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in `checkEnumArithmeticConversions`. Fix llvm#29217
…C mode Factored logic from `CheckImplicitConversion` into new methods `Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in `checkEnumArithmeticConversions`. Fix llvm#29217
…C mode Factored logic from `CheckImplicitConversion` into new methods `Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in `checkEnumArithmeticConversions`. Fix llvm#29217
@llvm/issue-subscribers-c Author: None (llvmbot)
| | |
| --- | --- |
| Bugzilla Link | [28847](https://llvm.org/bz28847) |
| Version | trunk |
| OS | All |
| Reporter | LLVM Bugzilla Contributor |
| CC | @mmdriley |
Extended DescriptionConsider this program (test.c) enum foo_t { enum bar_t { int main(void) {
} If I compile this as C code, I only get a warning for the first comparison. If I compile in C++ mode, I get a warning for all three. $ clang -Wall test.c I think the warnings should be emitted in C mode too. Tested with gcc 4.9.2 and 3 warnings are emitted for C code: $ gcc -Wall test.c |
Extended Description
Consider this program (test.c)
If I compile this as C code, I only get a warning for the first comparison. If I compile in C++ mode, I get a warning for all three.
I think the warnings should be emitted in C mode too. Tested with gcc 4.9.2 and 3 warnings are emitted for C code:
The text was updated successfully, but these errors were encountered: