Recently at my company we ran into an error that I am having trouble understanding why it's actually an error. To us it seems as though this should compile just fine and allow us to explicitly instantiate a template of type bar::foo.
mainy.cxx
int foo(int);
namespace bar {
template T foo(T a, T){return a;}
}
namespace bar {
using ::foo;
}
template int bar::foo(int, int);
int main(){
return 0;
}
g++ error
[csteifel@host:~/test]1047 $ g++ mainy.cxx
mainy.cxx:10: error: 'int bar::foo(int, int)' should have been declared inside 'bar'
mainy.cxx:10: error: 'int bar::foo(int, int)' is not declared in '::'
We have confirmed that this is an error in gcc 4.8, 4.4 and clang 3.7 however it appears to work with Visual Studio 2015.
We ran into this problem when we tried to instantiate std::remove but had included before and has in it
namespace std {
using ::remove;
}
Any ideas on whats going on here?
Answer
Looks like this is related to an ancient bug in gcc, where you cannot explicitly instantiate a template by using ns::func, the only way was to do it using namespace ns { ... func; }. This was only recently fixed and with newer gcc your code will compile.
And by the way, contrary to what you are saying, your code compiles with clang 3.7.
No comments:
Post a Comment