OSDN Git Service

Do not use default initializer for union
authorYi Kong <yikong@google.com>
Thu, 11 May 2017 18:51:08 +0000 (11:51 -0700)
committerYi Kong <yikong@google.com>
Tue, 6 Jun 2017 22:43:56 +0000 (22:43 +0000)
The next Clang update complains about this code pattern. Rewrite default
constructor to explicitly initialize the union field instead of using
the default initializer.

Test: Build
Bug: 37752547
Change-Id: I22a2aa392d7f4803282baed832b0fa2f852016ac
(cherry picked from commit 4fdbdd1692a549a31382f33f5d529fd141453ea1)

libs/math/include/math/half.h

index 615b840..7682973 100644 (file)
@@ -56,8 +56,8 @@ namespace android {
  */
 class half {
     struct fp16 {
-        uint16_t bits = 0;
-        fp16() noexcept = default;
+        uint16_t bits;
+        explicit constexpr fp16() noexcept : bits(0) { }
         explicit constexpr fp16(uint16_t b) noexcept : bits(b) { }
         void setS(unsigned int s) noexcept { bits = uint16_t((bits & 0x7FFF) | (s<<15)); }
         void setE(unsigned int s) noexcept { bits = uint16_t((bits & 0xE3FF) | (s<<10)); }
@@ -68,11 +68,11 @@ class half {
     };
     struct fp32 {
         union {
-            uint32_t bits = 0;
+            uint32_t bits;
             float fp;
         };
-        fp32() noexcept = default;
-        explicit constexpr fp32(float f) : fp(f) { }
+        explicit constexpr fp32() noexcept : bits(0) { }
+        explicit constexpr fp32(float f) noexcept : fp(f) { }
         void setS(unsigned int s) noexcept { bits = uint32_t((bits & 0x7FFFFFFF) | (s<<31)); }
         void setE(unsigned int s) noexcept { bits = uint32_t((bits & 0x807FFFFF) | (s<<23)); }
         void setM(unsigned int s) noexcept { bits = uint32_t((bits & 0xFF800000) | (s<< 0)); }