[Development] RFC: more liberal 'auto' rules?

Matthew Woehlke mwoehlke.floss at gmail.com
Tue Dec 22 15:33:12 CET 2015


On 2015-12-22 05:26, Ziller Eike wrote:
> So, directly after the above example in Item 5, Item 6 in Effective
> Modern C++ continues with the examples of how you can shoot yourself
> in the foot _because_ you used auto. [...]
> 
> We have something similar in Qt:
> 
>     QString a = "ABC";
>     QString b = "abc";
>     auto result = a + b;
>     a.replace("A", "C");
>     qDebug() << result;
> 
> prints “CBCabc” instead of “ABCabc” when QT_USE_FAST_OPERATOR_PLUS is
> defined, because result is not a QString in that case.

Someone ought to note... one of the arguments for AAA is that it avoids
uninitialized variables. It's actually still AAA to write:

  auto result = QString{a + b};

...and in fact that is what AAA recommends when you need to ensure a
specific type.

-- 
Matthew




More information about the Development mailing list