[PATCH] D123009: [Sema] Enum conversion warning when one signed and other unsigned.
    Micah Weston via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Tue May  3 12:27:39 PDT 2022
    
    
  
red1bluelost added inline comments.
================
Comment at: clang/docs/ReleaseNotes.rst:113-114
   by unary operators.
+- ``-Wenum-conversion`` now warns on conversion of signed enum to unsigned enum
+  and unsigned enum to signed enum rather than ``-Wsign-conversion``.
 
----------------
aaron.ballman wrote:
> Minor tweak
Thanks!
================
Comment at: clang/test/Sema/enum-sign-conversion.c:6-8
+enum X { A,
+         B,
+         C };
----------------
aaron.ballman wrote:
> Unrelated formatting change?
Changed back.
================
Comment at: clang/test/Sema/enum-sign-conversion.c:14-18
+enum SE1 { N1 = -1 };
+enum SE2 { N2 = -2 };
+// Unsigned unums
+enum UE1 { P1 };
+enum UE2 { P2 };
----------------
aaron.ballman wrote:
> The second variants are unused.
Good catch, removed.
================
Comment at: clang/test/Sema/enum-sign-conversion.c:37-43
+unsigned f5(enum UE1 E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 'enum UE1' to 'unsigned int'}}
+}
+
+enum UE1 f6(unsigned E) {
+  return E; // signed-warning {{implicit conversion changes signedness: 'unsigned int' to 'enum UE1'}}
+}
----------------
aaron.ballman wrote:
> Shouldn't these not warn as well -- the underlying enum type is unsigned?
This is the case with 'win32' for the ABI. It has enum be signed as default. I changed the name of the verify to win32 to that it is easier to see that is the case.
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123009/new/
https://reviews.llvm.org/D123009
    
    
More information about the cfe-commits
mailing list