Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A storage class is not allowed in an explicit specialization

Tags:

c++

gcc

I have the following code in a header file that does not belong to a class:

template<typename Foo> static const Compl<Foo,bar> *foobar (const FBTYPE &x);

template<> static const Compl<typea,bar> *foobar<typea>(const FBTYPE &x) {
    return x.funcA();
}

template<> static const Compl<typeb,bar> *foobar<typeb>(const FBTYPE &x) {
    return x.funcB();
}

The code compiles just fine with older GCC versions but in newer ones I get this error message:

rsvt.h(672): error #3503: a storage class is not allowed in an explicit specialization
  template<> static const Compl<typea,bar> *foobar<typea>(const FBTYPE &x) {
             ^

Any idea why it works with older versions of GCC but not with newer ones? Also, how can I get it to work with GCC 5?

like image 819
RegedUser00x Avatar asked Dec 07 '16 13:12

RegedUser00x


1 Answers

The reason is in the following quote which is now in the C++ standard: [dcl.stc]/p1

A storage-class-specifier other than thread_local shall not be specified in an explicit specialization

like image 86
Marco A. Avatar answered Sep 19 '22 20:09

Marco A.