[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Deprecating C++ classes with static member functions
From: |
John W. Eaton |
Subject: |
Deprecating C++ classes with static member functions |
Date: |
Wed, 6 Jul 2016 14:23:12 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0 |
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
- Deprecating C++ classes with static member functions,
John W. Eaton <=