octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ deprecation and namespaces


From: Rik
Subject: Re: C++ deprecation and namespaces
Date: Thu, 7 Jul 2016 11:04:12 -0700

On 07/06/2016 02:01 PM, address@hidden wrote:
Subject:
Deprecating C++ classes with static member functions
From:
"John W. Eaton" <address@hidden>
Date:
07/06/2016 11:23 AM
To:
Octave Maintainers List <address@hidden>
CC:
address@hidden
List-Post:
<mailto:address@hidden>
Content-Transfer-Encoding:
7bit
Precedence:
list
MIME-Version:
1.0
Message-ID:
<address@hidden>
Content-Type:
text/plain; charset=utf-8; format=flowed
Message:
1

Suppose I have a class like this:

  class octave_foo
  {
  public:
    static void bar () { }
  };

and I want to put it in a proper C++ namespace, like this:

  namespace octave
  {
    class foo
    {
    public:
      static void bar () { }
    };
  }

Is there a convenient way to make the old name 'octave_foo::bar' an alias for octave::foo::bar so that it can be tagged with a deprecated attribute and the compiler will warn about using the old name?

With GCC, using

  __attribute__ ((deprecated ("msg")))
  typedef octave::foo octave_foo;

will warn for creating objects using the name octave_foo, but won't warn for calling the static function using the name octave_foo::bar.

If it's not possible to create instances of the class, then

  namespace octave_foo
  {
    __attribute__ ((deprecated ("msg")))
    auto bar = &octave::foo::bar;
  }

will work, though this requires a definition for each static function in the class, and it's a little weird because octave_foo was originally a class, not a namespace.

I don't see how to get warnings for class objects and static functions other than to write

  class
  __attribute__ ((deprecated ("msg")))
  octave_foo
  {
  public:
    __attribute__ ((deprecated ("msg")))
    static void bar () { octave::foo::bar (); }
  };

but that requires duplicating most (or all) of the class definition.

Am I missing something that would make this easier to do?

jwe

Conceptually, the attribute tags get applied to each object that needs to be deprecated which does mean that if a lot of individual objects are being deprecated then there will be a correspondingly large number of attribute tags to add.

"Perfect is the enemy of good".  Instead of being perfect, are there some reasonable assumptions we can make to decrease the number of tags we need to add?  For example, are most of the deprecations of deep internal functions that only Octave core programmers are going to encounter?  If that is the case then we are already aware and can make the changeover in the core and forget about adding deprecation tags to those functions.  Beyond that, how many instances are we actually considering?  If it is less than 25 it is probably still faster to just code up rather than research convoluted syntaxes.

Another possibility is simply not to be nice.  When the old function is removed then code using it will fail to compile with a large error saying "XXX:XXX does not exist".  This quite accurately points out what needs to be fixed and if we put a translation table up somewhere then a Google search for the error message will quickly locate how to change name A to name B in order to compile again.

Can you make use of the C preprocessor.  Could you define octave_foo to expand into calling #warning to issue a warning, followed by the correct prefix octave::foo?

Maybe something here helps,
Rik


reply via email to

[Prev in Thread] Current Thread [Next in Thread]