This issue appear during freeorion compilation. Test case compile fine with GCC 7 and Clang 5 but fail with GCC 8. $ cat StyleFactory.cpp namespace std { template <typename> class shared_ptr {}; class a; template <class> class b { a *g() const; shared_ptr<a> e; }; template <class f> a *b<f>::g() const { return e; } } $ g++ --version g++ (GCC) 8.0.1 20180123 (experimental) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -O2 -fPIC -std=c++11 -o StyleFactory.cpp.i.o -c StyleFactory.cpp StyleFactory.cpp: In member function ‘std::a* std::b< <template-parameter-1-1> >::g() const’: StyleFactory.cpp:8:48: error: cannot convert ‘const std::shared_ptr<std::a>’ to ‘std::a*’ in return template <class f> a *b<f>::g() const { return e; } ^ GCC 7 works fine. $ g++ --version g++ (GCC) 7.2.1 20180123 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -O2 -fPIC -std=c++11 -o StyleFactory.cpp.i.o -c StyleFactory.cpp $ echo $? 0 Clang 5 also work fine. $ clang++ --version clang version 5.0.1 Target: x86_64-unknown-linux-gnu Thread model: posix $ clang++ -O2 -fPIC -std=c++11 -o StyleFactory.cpp.i.o -c StyleFactory.cpp $ echo $? 0
In this context e has a non-dependent type as shared_ptr<a> is a non-dependent type and shared_ptr<a> does not have a conversion to a*. So I don't see why this should accepted.
This changed with r253599.
The code is invalid, it only works with older versions of GCC and Clang because you never instantiate the function template and so the bug isn't detected. Obviously if you try to use the function then it won't compile, because there's no conversion. Why do you expect it to compile? See https://gcc.gnu.org/gcc-7/porting_to.html#hypothetical-instantiation