The following code is compiled by all versions of clang (and MSVC, and icc) and GCC up to 6.4.
GCC 7.1 and above reports an error, as if the function was instantiated.
#include <sstream>
#include <string>
// B.h
struct B {
void put(const char*);
};
// D.h
template<typename T>
struct D : public B {
D& operator=(T);
};
// D.c
template<typename T>
D<T>&
D<T>::operator=(T)
{
std::ostringstream oss;
put(oss.str()); // passing std::string to const char*
return *this;
}
int main()
{
D<int> di;
// without di = 42;
// GCC up to 6.4 compiles it.
// Every clang version compiles it.
// Also icc 16-19
// Also MSVC 19
//
// GCC 7.1 and higher reports "no matching function to call D<T>::put(std::string)"
// as if "di=42" was visible.
return 0;
}
(https://godbolt.org/z/xvNis4)
Is this a regression in GCC 7 ?