Make typechecking for enum+int compatibility stricter.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47005 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index c00779c..d01de2b 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -1709,10 +1709,14 @@
// C99 6.7.2.2p4: Each enumerated type shall be compatible with char,
// a signed integer type, or an unsigned integer type.
- // FIXME: need to check the size and ensure it's the same.
- if ((lcanon->isEnumeralType() && rcanon->isIntegralType()) ||
- (rcanon->isEnumeralType() && lcanon->isIntegralType()))
- return true;
+ if (lcanon->isEnumeralType() && rcanon->isIntegralType()) {
+ EnumDecl* EDecl = cast<EnumDecl>(cast<TagType>(lcanon)->getDecl());
+ return EDecl->getIntegerType() == rcanon;
+ }
+ if (rcanon->isEnumeralType() && lcanon->isIntegralType()) {
+ EnumDecl* EDecl = cast<EnumDecl>(cast<TagType>(rcanon)->getDecl());
+ return EDecl->getIntegerType() == lcanon;
+ }
return false;
}