ソースを参照

Kernel: KResultOr can use the same storage as the object for the error

Since it can only hold either an object or an error code, we can share
the same storage to hold either.
Tom 4 年 前
コミット
1d843c46eb
1 ファイル変更4 行追加2 行削除
  1. 4 2
      Kernel/KResult.h

+ 4 - 2
Kernel/KResult.h

@@ -172,8 +172,10 @@ public:
     }
     }
 
 
 private:
 private:
-    alignas(T) char m_storage[sizeof(T)];
-    KResult m_error;
+    union {
+        alignas(T) char m_storage[sizeof(T)];
+        KResult m_error;
+    };
     bool m_is_error { false };
     bool m_is_error { false };
     bool m_have_storage { false };
     bool m_have_storage { false };
 };
 };