https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70632
Bug ID: 70632 Summary: Wrong function name resolution using variadic template and additional template parameters Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: grumpy76 at web dot de Target Milestone: --- GCC Version -------------------- g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) - devtoolset 3 g++ (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2) - devtoolset 4 System ------ CentOS Linux release 7.2.1511 (Core) Command line to compile ----------------------- g++ -std=c++11 -Wall -Wextra -pedantic Minimal code to reproduce ------------------------- #include <iostream> #include <sstream> #include <string> template<typename T> std::ostringstream& appendToStream(std::ostringstream& stream, const T& value) { stream << value; return stream; } template<typename T, typename... Args> std::ostringstream& appendToStream(std::ostringstream& stream, const T& value, Args... args) { stream << value; return appendToStream(stream, args...); } template<typename... Args> std::string createMessage(Args... args) { std::ostringstream x; appendToStream(x, args...); return x.str(); } template<typename... Args> std::string foo(int, Args... args) { return std::string("foo with int: " + createMessage(args...)); } template<typename... Args> std::string foo(Args... args) { return std::string("foo without int: " + createMessage(args...)); } template<typename T, typename... Args> std::string bar(int, Args... args) { return std::string("bar with int: " + createMessage(args...)); } template<typename T, typename... Args> std::string bar(Args... args) { return std::string("bar without int: " + createMessage(args...)); } int main(int, char**) { int i(-1); std::cout << foo(i, "Hello ", "world") << std::endl; std::cout << foo("Hello ", "world") << std::endl; std::cout << bar<float>(i, "Hello ", "world") << std::endl; std::cout << bar<float>("Hello ", "world") << std::endl; } Output is --------- foo with int: Hello world foo without int: Hello world bar without int: -1Hello world bar without int: Hello world Output expected --------------- foo with int: Hello world foo without int: Hello world bar with int: Hello world bar without int: Hello world Comments -------- Code works as expected with - g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4) - clang version 3.4.2 (tags/RELEASE_34/dot2-final) - clang version 3.8.0 (tags/RELEASE_380/final) - msvc-14.0 (19.00.23918)