This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: Sanitize deprecation messages (PR 84195)


On Thu, Feb 15, 2018 at 04:04:45PM -0500, David Malcolm wrote:
> On Fri, 2018-02-09 at 13:01 +0000, Nick Clifton wrote:
> > +class escaped_string
> > +{
> > + public:
> > +  escaped_string () { m_owned = false; m_str = NULL; };
> > +  ~escaped_string () { if (m_owned) free (m_str); }
> > +  operator const char *() const { return (const char *) m_str; }
> > +  void escape (const char *);
> > + private:
> > +  char * m_str;
> > +  bool   m_owned;
> > +};
> 
> I'd hoped that instead of this we could have an escape_string function
> return an instance of a class that has responsibility for the "if
> (ownership) free" dtor, but I don't think C++89 supports that (I had a
> go at implementing it, but I think we'd need C++11's move semantics,
> rather than just the NRVO).

I think either gcc::unique_ptr does what you want here, or you could
use the same trick of having a copy ctor that takes a non constant
reference to implement this in C++98.

Thanks!

Trev


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]