Anders had a great idea: Once you pass the value of a PassRefPtr you should get an assertion if you try to use it. Idiomatically, we don’t use PassRefPtr after passing its value along. Its value is zero then, but in debug versions it could instead have a “known bad” value so we can catch incorrect uses. RefPtr could use the same feature. As could PassOwnPtr and OwnPtr.
Created attachment 66153 [details] Patch Here's a patch that does this for PassRefPtr. One thing we should figure out if it's valid to assign into a pointer that has been released. (See the editing change)
PassRefPtr is not used anymore but if this need to be extended for RefPtr then please decide accordingly. Else this can be marked as "RESOLVED WONTFIX". Thanks!
We now have ASan poisoning that serves a similar purpose (only in ASan builds, but it's good to avoid slowing down debug builds). Not in RefPtr though, but it's zeroed when moved out, so I'm not sure how this is applicable to RefPtr.
I think it depends if we want our code to treat RefPtr as "zeroed after moved out" or "invalid to read after moved out". When we want it actually zeroed we could use std::exchange(a, nullptr). But if we want to have the "can rely on it being zero" then we should leave it as is.