Interesting. On a related note, this fails as well:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
struct a {
};
template<const a& token>
struct b {
};
const a x = a();
const a& ref = x;
typedef b<ref> d;
int main() {
}
/Users/albatross/Documents/testpad/testpad.cpp:14: error: could not convert template argument 'ref' to 'const a&'
/Users/albatross/Documents/testpad/testpad.cpp:14: error: invalid type in declaration before ';' token
Templates have external linkage, type and non-type arguments also have to have external linkage. Non-extern const have internal linkage, hence the error.
Try:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
struct a {
};
template<a const& token>
struct b {
};
extern a const x = a();
//a x;
typedef b<x> c;
int main() {
}