Take the 2-minute tour ×

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 __attribute__ ((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?

share|improve this question
It works well in 4.8 and 4.7 and makes deprecating warning. Live code –  M M. Nov 5 '13 at 15:04
You are right, I was testing it with a slightly more complex example, it works for 4.7 and newer. Unfortunately Clang 3.3 emits an error. –  user2799037 Nov 5 '13 at 15:12
I would open a bug to clang. –  n.m. Nov 5 '13 at 16:02
@n.m.: Yes, it seems a bug, however it's just an extension and they've not promised it works with using. See here –  M M. Nov 5 '13 at 18:10
add comment

1 Answer

up vote 1 down vote accepted

GCC does support deprecating template alias since version 4.7. This is a test case comparing typedef and template alias:

template <class T>
struct NewClassName
    // ...

template <class T> using OldClassNameUsing __attribute__ ((deprecated))
  = NewClassName<T>;

typedef NewClassName<int> OldClassNameTypedef __attribute__ ((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 3.3 and 3.4 from SVN r194323. The corresponding feature request is http://llvm.org/bugs/show_bug.cgi?id=17862 Clang does still not support this feature with version 3.4 and SVN r200869 (begin of February 2014).

share|improve this answer
add comment

Your Answer


