https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67182
Bug ID: 67182 Summary: Initialising map with disabled copy elision yields unexpected results. Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vrgo at wp dot pl Target Milestone: --- The below code results in creating a map which contains only a single (incorrect) key-value pair instead of 3. Code: #include <map> #include <iostream> struct X { int x; int y; bool operator<(const X& other) const { return x < other.x; } }; int main() { std::map<X, int> detailsMap = { { X{1, 2}, 7 }, { X{3, 4}, 7 }, { X{5, 6}, 7 } }; std::cout << detailsMap.size() << std::endl; auto f = *(detailsMap.begin()); std::cout << f.first.x << " " << f.first.y << std::endl; } Invocation: $ g++ prog.cc -Wall -Wextra -I/usr/local/sprout -std=c++11 -fno-elide-constructors Output: 1 0 0 When I switch off "-fno-elide-constructors" or when I manually add copy and move constructors to struct X, 'detailsMap' correctly contains 3 given elements instead of one with some kind of "default" values (X::x = 0 and X::y = 0). I wasn't able to reproduce this problem with other containers like std::set or std::vector. It seems that this behaviour has been introduced in GCC 5.1.0 (I don't have this problem with GCC 4.9.2). I have tried it here: http://melpon.org/wandbox/permlink/El3p1eAcZ3azCsFi