// v.h
extern int const j;
template<int> extern int const i; // a "templated" extern int const
// v.cpp
#include "v.h"
extern int constexpr j = 42;
template<> extern int constexpr i<0> = 666; // error with gcc, but OK with clang
// main.cpp
#include "v.h"
int main()
{
auto k = j; // 42
k = i<0>; // 666 with clang
}
This code is fine with clang, but an error with gcc ("explicit template specialization cannot have a storage class"), probably due to 10.1.1 p1 last sentence.
The simple concept behind i is to have a "templated" j.
Of course the template parameters of i could be anything and the type should generally be of literal type so that constexpr in the definition is valid.
I see no reason why this should not be possible.
But 10.1.1 p1 forbids the storage class specifier extern in an explicit template specialization.
So gcc seems to be right, clang seems to be wrong but gets the idea and compiles successfully.
I haven't found a defect report on this, and nothing in this forum.
I have posted this issue on stackoverflow but with no solution so far (
https://stackoverflow.com/questions/46752714/erroneous-explicit-template-specialization-of-variable-template-in-gcc).
Just like clang I think this code should be possible.
So I suggest that an exception is made in the afore mentioned sentence for explicit specializations of variable templates declared extern.