I have a weird compilation error on gcc-4.9.2, where the same code worked on other compilers, like gcc-4.8 or any clang I could get hold of. The problem is related to non-type template-arguments. So consider this:
#include <iostream>
#include <cstddef>
int templateParam;
template <int &D> struct TestTemplate {
int value() {}
};
template <> int TestTemplate<templateParam>::value() {
return templateParam;
}
TestTemplate<templateParam> testVariable;
int main() {
std::cout << testVariable.value() << "\n";
return 0;
}
I get the following error with gcc-4.9.2:
prog.cpp:10:17: error: prototype for 'int TestTemplate<D>::value() [with int& D = (* & templateParam)]' does not match any in class 'TestTemplate<(* & templateParam)>'
template <> int TestTemplate<templateParam>::value() {
^
prog.cpp:7:9: error: candidate is: int TestTemplate<D>::value() [with int& D = (* & templateParam)]
int value() {}
^
these two ideones make it clearer:
Is this a compiler bug?
Is this a compiler bug?
Yes, I think it was https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63658 and will be fixed in the next release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With