Hi all,

On Sat, 11 Apr 2026 12:40:56 +0800 Chris Dumez via webkit-dev 
<[email protected]> wrote:

> I totally support. It is already in the safer cpp guidelines.

+1, and at least in the GTK/WPE port code we have been actively
suggesting to avoid "auto" in this case during patch review.
 
> > On Apr 11, 2026, at 12:03 PM, Brady Eidson via webkit-dev 
> > <[email protected]> wrote:
> > 
> > This has come up in countless patch reviews over the last few years, and 
> > it’s been obvious which way the winds are blowing.
> > 
> > Collectively I think we’ve decided it’s beneficial to have types related to 
> > lifecycle management explicitly pointed out in code, and we’ve been 
> > reviewing patches with that strong preference in mind for our common smart 
> > pointer types.
> > 
> > But at the same time, we think it's often ugly and verbose to fully spell 
> > out the full template of smart pointer types e.g.:
> > 
> >     RetainPtr<NSMutableArray> mutableArray = adoptNS([[NSMutableArray 
> > alloc] init]);
> > 
> > That’s a little verbose. So for quite some time we’d preferred:
> > 
> >     auto mutableArray = adoptNS([[NSMutableArray alloc] init]);
> > 
> > But at some point advances in C++ came along and our baseline compiler 
> > support for the project advanced to the point where the template goop isn’t 
> > necessary.
> > So it follows, it’s extremely common review feedback as of late is to use 
> > `RetainPtr` instead:
> > 
> >     RetainPtr mutableArray = adoptNS([[NSMutableArray alloc] init]);
> > 
> > I propose we make this a formal style rule. Update 
> > https://webkit.org/code-style-guidelines/ with examples like:
> > 
> >     auto foo = adoptNS([[SomeClass alloc] init]); // Error
> >     RetainPtr foo = adoptNS([[SomeClass alloc] init]); // The fix
> > 
> >     auto foo = adoptRef(*new SomeClass); // Style error
> >     Ref foo = adoptRef(*new SomeClass); // The fix
> > 
> >     auto foo = adoptRef(new SomeClass); // Style error
> >     RefPtr foo = adoptRef(new SomeClass); // The fix
> > 
> > And it’s even a rule that is trivially enforceable by `CheckWebKitStyle`
> > 
> > Assuming there’s no objection, I’ll be preparing patches for the script and 
> > the website soon.

Cheers,
—Adrián

Attachment: signature.asc
Description: PGP signature

_______________________________________________
webkit-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to