[llvm] [Support][JSON] Fix ObjectKey ownership and Value assignment bugs (PR #214104)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 01:50:39 PDT 2026


================
@@ -372,12 +372,7 @@ class Value {
             Value * = nullptr>
   Value(const T &V) : Value(toJSON(V)) {}
 
-  Value &operator=(const Value &M) {
-    destroy();
-    copyFrom(M);
-    return *this;
-  }
-  Value &operator=(Value &&M) {
+  Value &operator=(Value M) {
----------------
jh7370 wrote:

It's probably worth a comment explaining why this is taking by value, since nested values aren't going to immediately spring to anybody's mind when reading this code.

Did you consider another approach of moving the current contents of `this` into a temporary local `Value`, so that a nested value can be copied from/moved from safely? The local `Value` would then be destroyed naturally at the end of the function, after the input `M` has been copied/moved from. I don't know if it would be an improvement or not, but it would allow keeping the slightly-more-idiomatic separate copy/move assignment operators.

https://github.com/llvm/llvm-project/pull/214104


More information about the llvm-commits mailing list