#include<vector>
struct A{};
int main() {
std::vector<A>a;
a.emplace_back(0, 0);
}
Compiling this code with -std=c++17
, the error below is shown:
/usr/include/c++/13/bits/new_allocator.h:187:11: error: new initializer expression list treated as compound expression [-fpermissive]
187 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/new_allocator.h:187:11: error: no matching function for call to ‘A::A(int)’
a.cpp:2:8: note: candidate: ‘constexpr A::A()’
2 | struct A{};
| ^
However, after I provided A(int)
for A
, the compilers tried to call A::A(int, int)
:
/usr/include/c++/13/bits/new_allocator.h:187:11: error: no matching function for call to ‘A::A(int, int)’
187 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cpp:3:5: note: candidate: ‘A::A(int)’
3 | A(int x) {}
| ^
Why did the compiler behave like that?