Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecate templated class name with template alias (type alias, using)?

I want to rename a templated class. To make the transition easier for the users, I'd like to keep the old class for one more version and mark it deprecated with the extensions from GCC / Clang (attribute deprecated). To avoid keeping an exact copy of the deprecated class, the use of template alias would be handy. Unfortunatley it does not seem to work. This is what I tried with Clang 3.3, GCC 4.7, and GCC 4.8:

template <class blabla>
struct NewClassName
{
    // ...
};

template <class blabla> using OldClassName [[deprecated]]
  = NewClassName<blabla>;

Do I miss something or is this just unsupported by the compilers? Is there an other idea to get deprecation warnings without copying the whole class?

like image 866
usr1234567 Avatar asked Nov 05 '13 14:11

usr1234567


1 Answers

GCC does support deprecating template alias since version 4.9 (since 4.7 with __attribute__(deprecated)). This is a test case comparing typedef and template alias:

template <class T>
struct NewClassName
{
    // ...
};

template <class T> using OldClassNameUsing [[deprecated]]
  = NewClassName<T>;

typedef NewClassName<int> OldClassNameTypedef [[deprecated]];

int main()
{
  OldClassNameUsing<int> objectUsing;
  OldClassNameTypedef objectTypedef;

  return 0;
}

The reason why it did not work for me was that I did not create an object of the OldClassNameUsing but accessed static members like OldClassNameUsing::myFunction(). This does never trigger a deprecation warning unless the function itself is deprecated.

Clang does not yet support deprecating a template alias - tested with version 13. The corresponding feature request is http://llvm.org/bugs/show_bug.cgi?id=17862 https://github.com/llvm/llvm-project/issues/18236.

like image 186
usr1234567 Avatar answered Sep 30 '22 00:09

usr1234567