[Libreoffice-commits] Make Regexpr class safer

Stephan Bergmann sbergman at redhat.com
Fri Aug 31 08:40:30 PDT 2012


On 08/31/2012 03:59 PM, Libreoffice Gerrit user wrote:
> New commits:
> commit 574ddaba5315816a5629550a0a12f9c694b79370
> Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
> Date:   Fri Aug 31 14:40:14 2012 +0200
>
>      Make Regexpr class safer
>
>      Make copy constructor and copy operator private
>
>      Change-Id: Ifdaff6d74bebb0406432d470c84d221f2c06ba94
>      Reviewed-on: https://gerrit.libreoffice.org/519
>      Reviewed-by: Andras Timar <atimar at suse.com>
>      Tested-by: Andras Timar <atimar at suse.com>
>
> diff --git a/regexp/inc/regexp/reclass.hxx b/regexp/inc/regexp/reclass.hxx
> index f61112d..4be52bb 100644
> --- a/regexp/inc/regexp/reclass.hxx
> +++ b/regexp/inc/regexp/reclass.hxx
> @@ -357,6 +357,9 @@ class REGEXP_DLLPUBLIC Regexpr
>       sal_Bool iswordend(const sal_Unicode *d, sal_Unicode *string, sal_Int32 ssize);
>       void set_list_bit(sal_Unicode c, sal_Unicode *b);
>
> +    Regexpr(const Regexpr&);
> +    Regexpr& operator=(const Regexpr&);
> +
>   public:
>       // constructors
>       Regexpr( const ::com::sun::star::util::SearchOptions & rOptions,

FYI, the standard idiom is to privately derive the class from 
boost::noncopyable instead.

One general advantage of doing it that way is that at least with Clang 
3.2 --std=c++11, it does not prevent the compiler from flagging a 
class's unused private fields in a compilation unit that sees 
definitions for all of that class's declared member functions.  That is,

   class Foo: private boost::noncopyable {
     int n;
   public:
     Foo() {}
   };

will cause

   warning: private field 'n' is not used [-Wunused-private-field]

  while

   class Foo {
     int n;
     Foo(Foo const &);
   public:
     Foo() {}

will not.

Stephan


More information about the LibreOffice mailing list