[RFC] Using std::unique_ptr and std::make_unique in our code

Pedro Alves pedro@palves.net
Mon Jul 11 10:56:52 GMT 2022


Hi!

On 2022-07-08 9:46 p.m., David Malcolm via Gcc wrote:
> -				    pending_diagnostic *d,
> +				    std::unique_ptr<pending_diagnostic> d,

I see that you didn't add any typedef for std::unique_ptr<foo> in this patch.  It will be
inevitable that people will start adding them, for conciseness, IME, though.  To avoid diverging
naming styles for such typedefs in the codebase, GDB settled on using the "_up" suffix (for Unique Pointer)
quite early in the C++11 conversion, and we use such typedefs pervasively nowadays.  For example, for the type
above, we'd have:

  typedef std::unique_ptr<pending_diagnostic> pending_diagnostic_up;

and then:

 -				    pending_diagnostic *d,
 +				    pending_diagnostic_up d,

I would suggest GCC have a similar guideline, before people start using foo_ptr,
bar_unp, quux_p, whatnot diverging styles.

And it would be nice if GCC followed the same nomenclature style as GDB, so we could
have one single guideline for the whole GNU toolchain, so people moving between codebases
only had to learn one guideline.

Pedro Alves


More information about the Gcc mailing list