Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-08 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 08, 2023 at 10:13:39AM +, Jonathan Wakely wrote: > On Wed, 8 Mar 2023 at 07:25, Richard Biener wrote: > > > > On Wed, 8 Mar 2023, Alexander Monakov wrote: > > > > > > > > On Tue, 7 Mar 2023, Jonathan Wakely wrote: > > > > > > > > Shouldn't this use the idiom suggested in ansidecl.h,

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-08 Thread Jonathan Wakely via Gcc-patches
On Wed, 8 Mar 2023 at 07:25, Richard Biener wrote: > > On Wed, 8 Mar 2023, Alexander Monakov wrote: > > > > > On Tue, 7 Mar 2023, Jonathan Wakely wrote: > > > > > > Shouldn't this use the idiom suggested in ansidecl.h, i.e. > > > > > > > > private: > > > > DISABLE_COPY_AND_ASSIGN (auto_mpfr);

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Richard Biener via Gcc-patches
On Wed, 8 Mar 2023, Alexander Monakov wrote: > > On Tue, 7 Mar 2023, Jonathan Wakely wrote: > > > > Shouldn't this use the idiom suggested in ansidecl.h, i.e. > > > > > > private: > > > DISABLE_COPY_AND_ASSIGN (auto_mpfr); > > > > > > Why? A macro like that (or a base class like boost::n

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Marek Polacek via Gcc-patches
On Tue, Mar 07, 2023 at 09:54:08PM +, Jonathan Wakely via Gcc-patches wrote: > On Tue, 7 Mar 2023 at 21:52, Alexander Monakov wrote: > > > > > > On Tue, 7 Mar 2023, Jonathan Wakely wrote: > > > > > > Shouldn't this use the idiom suggested in ansidecl.h, i.e. > > > > > > > > private: > > > >

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Jonathan Wakely via Gcc-patches
On Tue, 7 Mar 2023 at 21:52, Alexander Monakov wrote: > > > On Tue, 7 Mar 2023, Jonathan Wakely wrote: > > > > Shouldn't this use the idiom suggested in ansidecl.h, i.e. > > > > > > private: > > > DISABLE_COPY_AND_ASSIGN (auto_mpfr); > > > > > > Why? A macro like that (or a base class like bo

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Alexander Monakov via Gcc-patches
On Tue, 7 Mar 2023, Jonathan Wakely wrote: > > Shouldn't this use the idiom suggested in ansidecl.h, i.e. > > > > private: > > DISABLE_COPY_AND_ASSIGN (auto_mpfr); > > > Why? A macro like that (or a base class like boost::noncopyable) has > some value in a code base that wants to work fo

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Jonathan Wakely via Gcc-patches
On Tue, 7 Mar 2023 at 19:15, Alexander Monakov wrote: > > Hi, > > On Mon, 6 Mar 2023, Richard Biener via Gcc-patches wrote: > > > --- a/gcc/realmpfr.h > > +++ b/gcc/realmpfr.h > > @@ -24,6 +24,26 @@ > > #include > > #include > > > > +class auto_mpfr > > +{ > > +public: > > + auto_mpfr () { mpf

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Alexander Monakov via Gcc-patches
Hi, On Mon, 6 Mar 2023, Richard Biener via Gcc-patches wrote: > --- a/gcc/realmpfr.h > +++ b/gcc/realmpfr.h > @@ -24,6 +24,26 @@ > #include > #include > > +class auto_mpfr > +{ > +public: > + auto_mpfr () { mpfr_init (m_mpfr); } > + explicit auto_mpfr (mpfr_prec_t prec) { mpfr_init2 (m_mp

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Jakub Jelinek via Gcc-patches
On Tue, Mar 07, 2023 at 07:51:03PM +0100, Bernhard Reutner-Fischer wrote: > While it's a nice idea, there have been resentments towards (visible) > C++ in the fortran frontend and especially the library, i think. I thought libgfortran is written in C and Fortran and doesn't use gmp/mpfr, so this d

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-07 Thread Bernhard Reutner-Fischer via Gcc-patches
On Mon, 6 Mar 2023 11:29:30 + (UTC) Richard Biener via Gcc-patches wrote: > On Mon, 6 Mar 2023, Jakub Jelinek wrote: > > > On Mon, Mar 06, 2023 at 11:01:18AM +, Richard Biener wrote: > > > + auto_mpfr &operator=(const auto_mpfr &) = delete; > > > + auto_mpz &operator=(const auto_mpz

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-06 Thread Richard Biener via Gcc-patches
On Mon, 6 Mar 2023, Jakub Jelinek wrote: > On Mon, Mar 06, 2023 at 11:01:18AM +, Richard Biener wrote: > > + auto_mpfr &operator=(const auto_mpfr &) = delete; > > + auto_mpz &operator=(const auto_mpz &) = delete; > > Just formatting nit, space before (. > > Looks like nice improvement and

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-06 Thread Jakub Jelinek via Gcc-patches
On Mon, Mar 06, 2023 at 11:01:18AM +, Richard Biener wrote: > + auto_mpfr &operator=(const auto_mpfr &) = delete; > + auto_mpz &operator=(const auto_mpz &) = delete; Just formatting nit, space before (. Looks like nice improvement and thanks Jonathan for the suggestions ;) Jakub

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-06 Thread Jonathan Wakely via Gcc-patches
On Mon, 6 Mar 2023 at 11:01, Richard Biener wrote: > > On Mon, 6 Mar 2023, Jonathan Wakely wrote: > > > On Mon, 6 Mar 2023 at 10:11, Richard Biener wrote: > > > > > > The following adds two RAII classes, one for mpz_t and one for mpfr_t > > > making object lifetime management easier. Both former

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-06 Thread Richard Biener via Gcc-patches
r. OK, it might be OK to mpfr_clear() twice and/or mpfr_clear/mpfr_init again. Quite possibly mpfr_init should get the same treatmen, mixing auto_* with explicit lifetime management is bad. > > + > > + auto_mpfr (const auto_mpfr &) = delete; > > This class has an implic

Re: [PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-06 Thread Jonathan Wakely via Gcc-patches
On Mon, 6 Mar 2023 at 10:11, Richard Biener wrote: > > The following adds two RAII classes, one for mpz_t and one for mpfr_t > making object lifetime management easier. Both formerly require > explicit initialization with {mpz,mpfr}_init and release with > {mpz,mpfr}_clear. > > I've converted two

[PATCH] [RFC] RAII auto_mpfr and autp_mpz

2023-03-06 Thread Richard Biener via Gcc-patches
The following adds two RAII classes, one for mpz_t and one for mpfr_t making object lifetime management easier. Both formerly require explicit initialization with {mpz,mpfr}_init and release with {mpz,mpfr}_clear. I've converted two example places (where lifetime is trivial). I've sofar only bui