[PATCH] D38145: Suppress Wsign-conversion for enums with matching underlying type

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 21 12:31:44 PDT 2017


erichkeane added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:8176
+      // underlying type, so that when someone specifies the type as
+      // "unsigned" it doesn't cause sign-conversion type warnings.
       if (!Enum->isCompleteDefinition())
----------------
efriedma wrote:
> Explicitly referencing sign-conversion warnings here isn't really helpful.  Maybe something more like "Incomplete enums without definitions can have an explicitly specified underlying type. Use that type here to compute the range."
Ok, got it.  I DO note that (IIRC) enums with an underlying type are not considered 'incomplete', so I modified your text slightly.  Thanks for the help.


================
Comment at: test/SemaCXX/sign-conversion.cpp:21
+  return foo;
+}
----------------
efriedma wrote:
> There's an existing file test/SemaCXX/warn-sign-conversion.cpp for C++ sign-conversion tests.
Thanks for pointing that out! Unfortunately, that file is very dependent on it being C++98, and this test requires c++11 or greater.  I DID rename the test file to better match that one however.


================
Comment at: test/SemaCXX/warn-sign-conversion-cpp11.cpp:11
+  // For a non-defined enum, use the underlying type.
+  enum u8 : char;
+  u8 foo{static_cast<u8>(0)};
----------------
efriedma wrote:
> The signedness of "char" can vary based on the host; probably simplest to write out "signed char".
Right, good catch.


https://reviews.llvm.org/D38145





More information about the cfe-commits mailing list