Re: [Libreoffice] final and override

2011-11-28 Thread Stephan Bergmann

On 11/27/2011 08:58 PM, Noel Grandin wrote:

I see the Mozilla project is adding MOZ_FINAL and MOZ_OVERRIDE macros
to help control method overriding in their codebase

http://whereswalden.com/2011/11/16/introducing-moz_override-to-annotate-virtual-functions-which-override-base-class-virtual-functions/
http://whereswalden.com/2011/11/26/introducing-moz_final-prevent-inheriting-from-a-class-or-prevent-overriding-a-virtual-function/

Would such things be useful additions to the LibreOffice codebase?


In principle, yes.  Like happened with features of the old C++ Standard 
that only made it slowly into the various compilers (the infamous 
VOS_NAMESPACE etc. stuff, e.g.), we will likely need macros for new 
features that can be enabled for compilers that already understand them, 
without breaking the code for legacy compilers.


However, given that override and final will only make it into GCC 4.7 
(according to http://wiki.apache.org/stdcxx/C++0xCompilerSupport), it 
might still be a bit early to address them.


Stephan
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] final and override

2011-11-28 Thread Michael Meeks

On Mon, 2011-11-28 at 09:03 +0100, Stephan Bergmann wrote:
 VOS_NAMESPACE etc. stuff, e.g.), we will likely need macros for new 
 features that can be enabled for compilers that already understand them, 
 without breaking the code for legacy compilers.

I believe the Mozilla guys augment this stuff by having an LLVM plugin
that does the validation of the keywords on top of the compiler. That
seems like a sensible approach to me.

On the other hand; I'd (personally) prefer to use some defines to
create the 'override' and 'final' keywords (as they will be in future).
Defining them to 'virtual' or even empty would do, if they are not
present in the compiler. cf. glib's provision of a stock 'inline'.

That should help reduce code thrash, and hideous ugliness ;-) keeping
us closer to more readable, standard C++.

HTH,

Michael.

-- 
michael.me...@suse.com  , Pseudo Engineer, itinerant idiot

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] final and override

2011-11-28 Thread Stephan Bergmann

On 11/28/2011 11:25 AM, Michael Meeks wrote:

On the other hand; I'd (personally) prefer to use some defines to
create the 'override' and 'final' keywords (as they will be in future).
Defining them to 'virtual' or even empty would do, if they are not
present in the compiler. cf. glib's provision of a stock 'inline'.

That should help reduce code thrash, and hideous ugliness ;-) keeping
us closer to more readable, standard C++.


One nitpick:  While it would keep the code surely more readable, it 
would make it less standard.  For one, override and final are 
technically not keywords in C++11, so a correct program that used them 
as identifiers would be broken if we defined them to be empty (for a 
compiler not yet supporting them).  For another, if override and final 
/were/ keywords, defining them in any way would result in undefined 
behaviour.


Stephan
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] final and override

2011-11-28 Thread Michael Meeks

On Mon, 2011-11-28 at 11:42 +0100, Stephan Bergmann wrote:
 On 11/28/2011 11:25 AM, Michael Meeks wrote:
  On the other hand; I'd (personally) prefer to use some defines to
  create the 'override' and 'final' keywords (as they will be in future).
  Defining them to 'virtual' or even empty would do, if they are not
  present in the compiler. cf. glib's provision of a stock 'inline'.
...
 One nitpick:  While it would keep the code surely more readable, it 
 would make it less standard.  For one, override and final are 
 technically not keywords in C++11, so a correct program that used them 
 as identifiers would be broken if we defined them to be empty (for a 
 compiler not yet supporting them).

Sure - but I suspect the instance count of that is really low in our
nFinal aOverride world; a quick:

git grep final | grep \.[ch]xx
git grep override | grep \.[ch]xx

Shows almost no problems here. 

   For another, if override and final /were/ keywords, defining them in
 any way would result in undefined behaviour.

Sure - which is why we'd do that for old compiler versions only; that
is what glib does for 'inline' - quite successfully. The main downside
to this might be the odd error messages when someone does:

bool final = false;

;-) but - apparently people don't do that. Either way, I know which I
prefer:

finalbool methodFoo();
virtual  char methodBaz();
override int  methodBaa();
vs.
SAL_FINALbool methodFoo()
virtual  char methodBaz();
SAL_OVERRIDE int  methodBaa()

But, since there is (as yet) no patch, it's hardly worth discussing.

;-)

Michael.

-- 
michael.me...@suse.com  , Pseudo Engineer, itinerant idiot

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] final and override

2011-11-28 Thread Stephan Bergmann

On 11/28/2011 01:27 PM, Michael Meeks wrote:

Sure - which is why we'd do that for old compiler versions only


...where it would still result in undefined behaviour, technically (note 
the nitpick, was meant somewhat tongue-in-cheek).



finalbool methodFoo();
virtual  char methodBaz();
override int  methodBaa();


(Note that final and override go at the end of the declaration.)

Stephan
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] final and override

2011-11-28 Thread Pierre-André Jacquod

Hello,


However, given that override and final will only make it into GCC 4.7
(according to http://wiki.apache.org/stdcxx/C++0xCompilerSupport), it


according to gcc.gnu.org too..

but since it seems that MSCV (according the same wiki) supports it / 
will support it, why not just wait a bit and then use it directly, 
setting a minimal compiler version ? This would allow a cleaner code, 
not having to take into account before implementation status. (would 
also be valid for other major features ) Most probably a too harsh 
approach ?

regards
Pierre-André

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] final and override

2011-11-28 Thread Stephan Bergmann

On 11/28/2011 08:10 PM, Pierre-André Jacquod wrote:

but since it seems that MSCV (according the same wiki) supports it /
will support it, why not just wait a bit and then use it directly,
setting a minimal compiler version ? This would allow a cleaner code,
not having to take into account before implementation status. (would
also be valid for other major features ) Most probably a too harsh
approach ?


We need to support rather old GCC version on Mac OS X.

Stephan
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


[Libreoffice] final and override

2011-11-27 Thread Noel Grandin
Hi

I see the Mozilla project is adding MOZ_FINAL and MOZ_OVERRIDE macros
to help control method overriding in their codebase

http://whereswalden.com/2011/11/16/introducing-moz_override-to-annotate-virtual-functions-which-override-base-class-virtual-functions/
http://whereswalden.com/2011/11/26/introducing-moz_final-prevent-inheriting-from-a-class-or-prevent-overriding-a-virtual-function/

Would such things be useful additions to the LibreOffice codebase?

-- Noel Grandin
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice