[Bug c++/60437] [C++11] Bogus "error: no matching function for call to 'X::X(<brace-enclosed initializer list>)'"
neoncat6 at outlook dot com
gcc-bugzilla@gcc.gnu.org
Wed Jan 29 16:20:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60437
--- Comment #4 from Foo Bar <neoncat6 at outlook dot com> ---
Seems like I found same issue on gcc 9.1.1.... Both MSVC 2019 and clang 9 can
compile this source without any error.
#include <iostream>
#include <vector>
class Abc {
public:
Abc(std::initializer_list<int> il = {}) : vec(il) {}
std::vector<int> vec;
};
int main(void) {
Abc abc{ 1, 2, 3, 4 };
for (auto num : abc.vec)
std::cout << num << std::endl;
return 0;
}
Error message:
$ g++ -Wall -std=c++11 il_def_arg.cpp
il_def_arg.cpp: In function ‘int main()’:
il_def_arg.cpp:12:22: error: no matching function for call to
‘Abc::Abc(<brace-enclosed initializer list>)’
12 | Abc abc{ 1, 2, 3, 4 };
| ^
il_def_arg.cpp:6:2: note: candidate: ‘Abc::Abc(std::initializer_list<int>)’
6 | Abc(std::initializer_list<int> il = {}) : vec(il) {}
| ^~~
il_def_arg.cpp:6:2: note: candidate expects 1 argument, 4 provided
il_def_arg.cpp:4:7: note: candidate: ‘Abc::Abc(const Abc&)’
4 | class Abc {
| ^~~
il_def_arg.cpp:4:7: note: candidate expects 1 argument, 4 provided
il_def_arg.cpp:4:7: note: candidate: ‘Abc::Abc(Abc&&)’
il_def_arg.cpp:4:7: note: candidate expects 1 argument, 4 provided
More information about the Gcc-bugs
mailing list