The following code is accepted by g++ (14.2.1):
#include <vector>template<typename T>void foo(T i, std::vector<int> &v = {}){ }int main(){ std::vector<int> v; foo(3, v);}
but rejected by clang (19.1.7) with:
non-const lvalue reference to type 'std::vector<int>' cannot bind to an initializer list temporary
If I rely on the default argument (by omitting the 2nd parameter), both compilers reject the code, which makes sense since an attempt is made to bind a non-const lvalue reference to an rvalue.
Is clang correct by rejecting the code or is g++ correct by accepting the code?