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 @@ -13534,9 +13534,10 @@ // Fall through for non-constants to give a sign conversion warning. } - if ((TargetRange.NonNegative && !LikelySourceRange.NonNegative) || - (!TargetRange.NonNegative && LikelySourceRange.NonNegative && - LikelySourceRange.Width == TargetRange.Width)) { + if ((!isa(Target) || !isa(Source)) && + ((TargetRange.NonNegative && !LikelySourceRange.NonNegative) || + (!TargetRange.NonNegative && LikelySourceRange.NonNegative && + LikelySourceRange.Width == TargetRange.Width))) { if (S.SourceMgr.isInSystemMacro(CC)) return; 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,25 @@ +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wenum-conversion -verify %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -Wconversion -verify %s + +// Signed enums +enum SE1 { N1 = -1 }; +enum SE2 { N2 = -2 }; +// Unsigned unums +enum UE1 { P1 }; +enum UE2 { P2 }; + +enum UE2 f1(enum UE1 E) { + return E; // expected-warning {{implicit conversion from enumeration type 'enum UE1' to different enumeration type 'enum UE2'}} +} + +enum SE1 f2(enum UE1 E) { + return E; // expected-warning {{implicit conversion from enumeration type 'enum UE1' to different enumeration type 'enum SE1'}} +} + +enum UE1 f3(enum SE1 E) { + return E; // expected-warning {{implicit conversion from enumeration type 'enum SE1' to different enumeration type 'enum UE1'}} +} + +enum SE2 f4(enum SE1 E) { + return E; // expected-warning {{implicit conversion from enumeration type 'enum SE1' to different enumeration type 'enum SE2'}} +}