http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54924
Bug #: 54924 Summary: Warn for std::string constructor with wrong size Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: da...@doublewise.net The constructor for std::string that takes an array of char and a size assumes that the array of char you pass in is at least as large as the size you specify. In other words, std::string str('0', 100) is undefined behavior. As I show in this example, the real issue can be much more subtle if escape characters are involved: http://stackoverflow.com/questions/164168/how-do-you-construct-a-stdstring-with-an-embedded-null/12884464#12884464 It would be nice if gcc warned when the size specified in the constructor exceeds the size of the array passed as the first argument.