A minimal example is:
#include <vector> class A { private: // where the real initialization happens void constructor_impl(int); void constructor_impl(const A&); public: A(const auto&... args) { (constructor_impl(args), ...); } }; int main() { A{0, A{1, 2}}; // correct construction A{""}; // wrong construction: compiles to an infinite recursion } I expect the wrong call A{""} to raise a compile error. But instead the compiler tries to cast "" to A and generates an infinite recursion. GCC, Clang and MSVC generates similar results, so it's unlikely to be a compiler bug.
Why does it happen? How can I refactor my code to avoid this issue?
void constructor_implmethod is private, and not an actual constructor. Try to better the define the actual (public) constructor, and not make it as general (i.e., without auto).constructor_implare not constructors. Making the only constructor explicit makes the code ill-formed, as it's desired.constructor_impldo you expectA{""}to use?""isn't convertible toint, so converting it toAseems to be the only possible way out.due to implicit conversionmight help future reader.