forked from OSchip/llvm-project
Make typechecking for enum+int compatibility stricter.
llvm-svn: 47005
This commit is contained in:
parent
2b90b0d09e
commit
a7bf7ed476
|
@ -1709,10 +1709,14 @@ bool ASTContext::typesAreCompatible(QualType lhs, QualType rhs) {
|
|||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -27,5 +27,9 @@ void foo() {
|
|||
int (*pf)[2];
|
||||
int (*pv)[i];
|
||||
pf = (i ? pf : pv);
|
||||
|
||||
enum {xxx,yyy,zzz} e, *ee;
|
||||
short x;
|
||||
ee = ee ? &x : ee ? &i : &e; // expected-warning {{pointer type mismatch}}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue