diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -13552,7 +13552,9 @@ *ICContext = true; } - return DiagnoseImpCast(S, E, T, CC, DiagID); + DiagnoseImpCast(S, E, T, CC, DiagID); + if (!isa(Target) || !isa(Source)) + return; } // Diagnose conversions between different enumeration types. diff --git a/clang/test/Sema/enum-enum-conversion.c b/clang/test/Sema/enum-enum-conversion.c new file mode 100644 --- /dev/null +++ b/clang/test/Sema/enum-enum-conversion.c @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wenum-conversion -DENUM_CONV %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -verify -Wconversion %s + +enum NE1 { N1 = -1 }; +enum NE2 { N2 = -2 }; +enum PE1 { P1 }; +enum PE2 { P2 }; + +enum PE2 f1(enum PE1 E) { +#ifdef ENUM_CONV + return E; // expected-warning {{implicit conversion from enumeration type 'enum PE1' to different enumeration type 'enum PE2'}} +#else + return E; // expected-warning {{implicit conversion from enumeration type 'enum PE1' to different enumeration type 'enum PE2'}} +#endif +} + +enum NE1 f2(enum PE1 E) { +#ifdef ENUM_CONV + return E; // expected-warning {{implicit conversion from enumeration type 'enum PE1' to different enumeration type 'enum NE1'}} +#else + return E; // expected-warning {{implicit conversion from enumeration type 'enum PE1' to different enumeration type 'enum NE1'}} expected-warning {{implicit conversion changes signedness: 'enum PE1' to 'enum NE1'}} +#endif +} + +enum PE1 f3(enum NE1 E) { +#ifdef ENUM_CONV + return E; // expected-warning {{implicit conversion from enumeration type 'enum NE1' to different enumeration type 'enum PE1'}} +#else + return E; // expected-warning {{implicit conversion from enumeration type 'enum NE1' to different enumeration type 'enum PE1'}} expected-warning {{implicit conversion changes signedness: 'enum NE1' to 'enum PE1'}} +#endif +} + +enum NE2 f4(enum NE1 E) { +#ifdef ENUM_CONV + return E; // expected-warning {{implicit conversion from enumeration type 'enum NE1' to different enumeration type 'enum NE2'}} +#else + return E; // expected-warning {{implicit conversion from enumeration type 'enum NE1' to different enumeration type 'enum NE2'}} +#endif +} \ No newline at end of file