[Fix] avoid unexpected throw in AttrInitEntry (#6128)
authorqiuhan <hanzz2007@hotmail.com>
Mon, 3 Aug 2020 19:29:55 +0000 (03:29 +0800)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2020 19:29:55 +0000 (12:29 -0700)
include/tvm/ir/attrs.h

index 4cdf8c5..d20ba4f 100644 (file)
@@ -337,6 +337,18 @@ struct AttrInitEntry {
   T* value_;
   // whether the value is missing.
   bool value_missing_{true};
+
+  AttrInitEntry() = default;
+
+  AttrInitEntry(AttrInitEntry&& other) {
+    type_key_ = other.type_key_;
+    key_ = other.key_;
+    value_ = other.value_;
+    value_missing_ = other.value_missing_;
+    // avoid unexpected throw
+    other.value_missing_ = false;
+  }
+
   // If the value is still missing in destruction time throw an error.
   ~AttrInitEntry() DMLC_THROW_EXCEPTION {
     if (value_missing_) {
@@ -463,7 +475,7 @@ class AttrInitVisitor {
     } else {
       opt.value_missing_ = true;
     }
-    return opt;
+    return std::move(opt);
   }
 
  private: