Reputation: 4765
clang++ (17.0.1) gives a warning for this code:
#include <iostream>
namespace {
void fun ()
{
std::cout << "fun\n";
}
} // namespace
template<class T>
void tfun (T)
{
fun();
}
template<> void tfun (int);
The warning goes away if fun
is not inside an anonymous namespace.
Is this a compiler bug?
See godbolt
Upvotes: 3
Views: 176
Reputation: 190
This is an annoying error, but it is still an error according to the compiler (and not a compiler bug IMHO).
From the compiler POV, if the template function tfun
is not instanciated, then the function fun
is not used anywhere. Like tfun
is not even there.
One of the possible fixes is to make fun
templated and instanciate it only if tfun
is instanciated. This is not the "fix" I like, but I can not come up with anything better.
Here is a compilable block of code:
#include <iostream>
namespace {
template<class T>
void fun ()
{
std::cout << "fun\n";
}
}
template<class T>
void tfun (T)
{
fun<T>();
}
Upvotes: 0