Mt19937 and default constructor cause incorrect class initialization?

I ran into an odd problem that appeared only in Release mode, but not in Debug mode (working with VS2015 RC). The second member of the Aggregate class gets initialized with the same values ​​as the first, although it must be initialized by default.

Even stranger, as soon as I changed Base() = default; on Base() {}; , strange behavior has disappeared. But they must be equivalent, right? I found a VS error?

I was able to bring to this:

 #include <iostream> #include <vector> #include <random> using namespace std; class Base { public: Base() = default; // elicits the odd behaviour on VS Release mode //Base() {}; // works Base(std::vector<int> m) : m(m) {}; size_t get_m() const { return m.size(); }; private: std::vector<int> m; std::mt19937 engine; }; class Aggregate { public: Aggregate() = default; Aggregate(Base one, Base two) : one(one), two(two) {}; Base get_one() const { return one; }; Base get_two() const { return two; }; private: Base one; Base two; }; Aggregate make_aggregate() { Base b1(std::vector<int> { 1, 2 }); Base b2(std::vector<int> { 3, 4, 5}); return Aggregate(b1, b2); }; int main() { Aggregate a1 = make_aggregate(); Base base = Base(); Aggregate a2(a1.get_one(), base); // a2.two.m should be empty and it is Aggregate a3(a1.get_one(), Base()); // a2.two.m should be empty but it set to a2.one.m // should print '2, 0', and it does: cout << a2.get_one().get_m() << ", " << a2.get_two().get_m() << endl; // prints '2, 2' on VS in Release mode! (and '2, 0' in Debug mode, and on clang): cout << a3.get_one().get_m() << ", " << a3.get_two().get_m() << endl; } 

I am here in the country of behavior undefined (for example, should there be mt19937 static?) or is my code good? Is this a VS error? clang-3.5 was ok with both with and without -g code.

+5
source share

All Articles