I just made a sample, which from my personal point of view should not compile, or at least give a warning, but Visual Studio 2017 does not give any warnings. The sample is following:
#include <stdexcept>
struct Foo {
Foo(int i) { throw std::runtime_error("Oh no:("); }
Foo(float f) {}
};
struct Bar {
Bar() {}
};
struct Baz {
Baz() : foo(5.0f) {}
Bar bar;
Foo foo = Foo(3);
Bar bar2;
};
int main()
{
Baz baz;
}
From my point of view (but I am not a language lawyer), the two initializations of foo (in-place vs initializer list) are ambiguous. So what are the rules in this case?