Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22228

Binding to initializer_list accepted by g++, but rejected by clang

$
0
0

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?


Viewing all articles
Browse latest Browse all 22228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>