I have code which is differently interpreted by g++ with the c++14
and c++17
standard flags:
#include
#include
The behavior changed since C++17.
Before C++17, the code works because std::vector has two template parameters (the 2nd one has the default argument std::allocator<T>
), while the template template parameter Vector
is declared to have only one, they don't match then the 2nd func
won't be considered.
Since C++17 (CWG 150), the default template arguments are allowed for a template template argument to match a template template parameter with fewer template parameters. That means both func
become valid candidates and then leads to ambiguity.
template<class T> class A { /* ... */ }; template<class T, class U = T> class B { /* ... */ }; template<template<class> class P> class X { /* ... */ }; X<A> xa; // OK X<B> xb; // OK in C++17 after CWG 150 // Error earlier: not an exact match