PSA: Deleting implicit conversion from raw pointer to rtc::scoped_refptr

Skip to first unread message

Niels Moller

Jan 20, 2022, 11:21:21 AMJan 20
Many webrtc objects are reference counted, both internally, and in the advertised C++ PeerConnection API, with references managed via the "smart pointer " type rtc::scoped_refptr (which predates std::shared_ptr, and works a bit different).

For historical reasons, the rtc::scoped_refptr class supports implicit conversion to and from raw pointer; one can pass a T* wherever a rtc::scoped_refptr<T> is expected and vice versa, and these implicit conversions makes ownership of objects much less visible.

I intend to delete implicit conversion in one direction, from raw pointer to rtc::scoped_refptr, soon, but at the earliest two weeks from now, February 3. The planned change is in, note that the special case of implicit conversion from nullptr is kept.

When this change lands, applications will need to change any existing implicit conversions to explicitly use the appropriate rtc::scoped_refptr constructor. For examples of what needed changes will look like, see, updating webrtc itself, and, updating chromium. The rtc::make_ref_counted utility used in a few places in webrtc will at some point be moved to webrtc's advertised api/ folder, but not right away.

Implicit conversion in the other direction, from rtc::scoped_refptr<T> to T*, without using the .get() method, will hopefully be deleted too, at some later time.

Please see for context and feedback.

/Niels Möller

Niels Moller

May 6, 2022, 3:13:22 AMMay 6
Preparations now complete for this next step, see, to be landed soon.

Please see for context and feedback.

Reply all
Reply to author
0 new messages