KDE_DEPRECATED

Brad King brad.king at kitware.com
Fri Mar 10 18:04:44 CET 2006


Christian Ehrlicher wrote:
> David Faure schrieb:
> 
>>>It is working, but KDE_DEPRECATED is placed behind the functions in most
>>>of the cases and I won't change this in every kdelibs-header...
>>
>>Well someone has to do it, and preferrably someone who can see the problematic instances... :)
>>
> 
> Ok, I'll take a look on this when makekdewidgets is working :)

I've found that a KDE_DEPRECATED-style macro is insufficient across 
compilers.  Some compilers want the decoration before the method and 
some want it after the method.  In VTK I created a "VTK_LEGACY" macro 
that surrounds the method declaration.

The full definition is shown below.  There is a "silent" mode to disable 
the warnings.  It also supports a "remove" mode in which deprecated code 
is removed from the build which is useful for making sure applications 
do not use any deprecated methods.

The header file declaring the method does this:

VTK_LEGACY(void MyMethod());

and the source file defining the method does this:

#ifndef VTK_LEGACY_REMOVE
void MyClass::MyMethod()
{
}
#endif

If someone is going to make a sweep through KDE's version of this I 
suggest a similar design be used...at least for the header file part but 
perhaps without the REMOVE support.

-Brad


// Define VTK_LEGACY macro to mark legacy methods where they are
// declared in their class.  Example usage:
//
//   // @deprecated Replaced by MyOtherMethod() as of VTK 5.0.
//   VTK_LEGACY(void MyMethod());
#if defined(VTK_LEGACY_REMOVE)
   // Remove legacy methods completely.  Put a bogus declaration in
   // place to avoid stray semicolons because this is an error for some
   // compilers.  Using a class forward declaration allows any number
   // of repeats in any context without generating unique names.
# define VTK_LEGACY(method) class vtkLegacyMethodRemoved
#elif defined(VTK_LEGACY_SILENT) || defined(VTK_WRAPPING_CXX)
   // Provide legacy methods with no warnings.
# define VTK_LEGACY(method) method
#else
   // Setup compile-time warnings for uses of deprecated methods if
   // possible on this compiler.
# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || 
(__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#  define VTK_LEGACY(method) method __attribute__((deprecated))
# elif defined(_MSC_VER) && _MSC_VER >= 1300
#  define VTK_LEGACY(method) __declspec(deprecated) method
# else
#  define VTK_LEGACY(method) method
# endif
#endif


More information about the Kde-buildsystem mailing list