Web lists-archives.com

auto QString(Builder) considered VERY HARMFUL


Today I fixed the third or so crash in KDE software due to the following 

const auto str = someString + anotherString;

What happens is that the type of str ends up being QStringBuilder 
instead of QString. The QStringBuilder is destroyed after the semicolon, 
and all access to "str" produces undefined behavior.
While I'm not a particularly big fan of using auto to hide variable 
types anyway, this kind of usage is just wrong and must be avoided. 
Please take care.