forked from OSchip/llvm-project
Warn about implicit conversions between values of different, named
enumeration types. Fixes <rdar://problem/8559831>. llvm-svn: 126183
This commit is contained in:
parent
c1b7775e0f
commit
a78f193e7e
|
@ -1154,6 +1154,9 @@ def warn_impcast_literal_float_to_integer : Warning<
|
|||
"implicit conversion turns literal floating-point number into integer: "
|
||||
"%0 to %1">,
|
||||
InGroup<DiagGroup<"literal-conversion">>, DefaultIgnore;
|
||||
def warn_impcast_different_enum_types : Warning<
|
||||
"implicit conversion from enumeration type %0 to different enumeration type "
|
||||
"%1">, InGroup<DiagGroup<"conversion">>;
|
||||
|
||||
def warn_cast_align : Warning<
|
||||
"cast from %0 to %1 increases required alignment from %2 to %3">,
|
||||
|
|
|
@ -2861,6 +2861,17 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
|
|||
return DiagnoseImpCast(S, E, T, CC, DiagID);
|
||||
}
|
||||
|
||||
// Diagnose conversions between different enumeration types.
|
||||
if (const EnumType *SourceEnum = Source->getAs<EnumType>())
|
||||
if (const EnumType *TargetEnum = Target->getAs<EnumType>())
|
||||
if ((SourceEnum->getDecl()->getIdentifier() ||
|
||||
SourceEnum->getDecl()->getTypedefForAnonDecl()) &&
|
||||
(TargetEnum->getDecl()->getIdentifier() ||
|
||||
TargetEnum->getDecl()->getTypedefForAnonDecl()) &&
|
||||
SourceEnum != TargetEnum)
|
||||
return DiagnoseImpCast(S, E, T, CC,
|
||||
diag::warn_impcast_different_enum_types);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -310,3 +310,24 @@ void test_8232669(void) {
|
|||
#define USER_SETBIT(set,bit) do { int i = bit; set[i/(8*sizeof(set[0]))] |= (1 << (i%(8*sizeof(set)))); } while(0)
|
||||
USER_SETBIT(bitset, 0); // expected-warning 2 {{implicit conversion changes signedness}}
|
||||
}
|
||||
|
||||
// <rdar://problem/8559831>
|
||||
enum E8559831a { E8559831a_val };
|
||||
enum E8559831b { E8559831b_val };
|
||||
typedef enum { E8559831c_val } E8559831c;
|
||||
enum { E8559831d_val } value_d;
|
||||
|
||||
void test_8559831_a(enum E8559831a value);
|
||||
void test_8559831(enum E8559831b value_a, E8559831c value_c) {
|
||||
test_8559831_a(value_a); // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
|
||||
enum E8559831a a1 = value_a; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
|
||||
a1 = value_a; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}}
|
||||
|
||||
test_8559831_a(value_c); // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}}
|
||||
enum E8559831a a2 = value_c; // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}}
|
||||
a2 = value_c; // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}}
|
||||
|
||||
test_8559831_a(value_d);
|
||||
enum E8559831a a3 = value_d;
|
||||
a3 = value_d;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue