diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 4 | ||||
-rw-r--r-- | clang/test/Sema/warn-outof-range-assign-enum.c | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 077282c1bf1..1d2ebad7881 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1149,7 +1149,7 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, return; if (const EnumType *ET = DstType->getAs<EnumType>()) - if (!Context.hasSameType(SrcType, DstType) && + if (!Context.hasSameUnqualifiedType(SrcType, DstType) && SrcType->isIntegerType()) { if (!SrcExpr->isTypeDependent() && !SrcExpr->isValueDependent() && SrcExpr->isIntegerConstantExpr(Context)) { @@ -1184,7 +1184,7 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, EI++; if (EI == EIend || EI->first != RhsVal) { Diag(SrcExpr->getExprLoc(), diag::warn_not_in_enum_assignment) - << DstType; + << DstType.getUnqualifiedType(); } } } diff --git a/clang/test/Sema/warn-outof-range-assign-enum.c b/clang/test/Sema/warn-outof-range-assign-enum.c index 43eea0cef41..edd4e372292 100644 --- a/clang/test/Sema/warn-outof-range-assign-enum.c +++ b/clang/test/Sema/warn-outof-range-assign-enum.c @@ -11,6 +11,24 @@ typedef enum CCTestEnum CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} +// Explicit cast should silence the warning. +static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} +static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning +static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning +static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning + +void SilenceWithCastLocalVar() { + CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} + CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning + CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning + CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning + + const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} + const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning + const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning + const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning +} + CCTestEnum foo(CCTestEnum r) { return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} } |