[Qt-creator] Using C++11 in Creator's source

Ziller Eike Eike.Ziller at digia.com
Wed Mar 5 12:09:10 CET 2014


On Mar 5, 2014, at 11:12 AM, Poenitz Andre <Andre.Poenitz at digia.com> wrote:

> 
> Ziller Eike wrote:
>> On Mar 4, 2014, at 2:09 PM, Daniel Teske <daniel.teske at digia.com> wrote:
>> 
>>> Hi,
>>> 
>>> since we have branched 3.1 from master, master no longer needs to support OS X
>>> 10.6. As such I propose, that we open up master for those C++11 features that
>>> are supported by VS 2010, g++ 4.5 and clang 3.1.
>>> 
>>> I think it's too early to require a newer version of Visual Studio, though
>>> requiring those 3 compilers gives us both *auto* and *lambda*.
>>> 
>>> I suspect that in practice the minimum g++ or clang version will be higher,
>>> since practically no one uses those versions any more.
>>> 
>>> We need to extend the coding rules for auto and lambda. Suggestions are
>>> welcome for that.
>> 
>> One rule for using “auto” that I’d like to establish, is to use it only “when the type is obvious when reading the code”.
>> Of course what that exactly means should be discussed and shown in some examples, and then it’s still up for interpretation.
>> E.g.:
>> 
>> Yes:
>> 
>> auto f = new FooBar;
>> auto a = new A;
>> auto myAction = menu->addAction(…);
>> auto it = list.const_iterator();
>> 
>> No:
>> 
>> auto i = 4; // the difference between “4;” and “4.;” is subtile with big consequences
> 
> What is obvious for some might unfortunately not be so obvious for others.
> 
> From the list of "Yes" cases I only fully agree with "auto it = list.const_iterator();"
> 
> I'd actually like to restrict the use of auto to cases where it "significantly" reduces
> typing and line noise (say, identifiers longer than x chars, and to cases where 
> it doesn't change meaning.

In my view the repetition in of the type in “A *a = new A;” is significant noise that is reduced by “auto *a = new A;”, even though it is not less to type.
But I suppose that example doesn’t have much relevance anyhow.

> Simple types ('int', 'bool', 'double' ... should never be 'auto'd', and I am tempted to
> include "simple Qt value types" like 'QString' in this section.

I’m not sure to which degree I agree, maybe we should look at specific examples there as well.

> For the pointer cases, we should spend a thought or two on possibly requiring 
> 
> auto *f = new FooBar;

Fine with me. Possibly use of foreach (auto ….) could be an exception to this.

> to keep the visual clue that this is a pointer that might (or might not) need some 
> cleanup. 
> 
> It would be nice if <F2> on 'auto' would jump to the definition of the 'real' type.
> 
> I'd also like to get some time to collect experience with the new toys before
> major existing hunks of code are converted.
> 
> Andre'

-- 
Eike Ziller, Senior Software Engineer - Digia, Qt
 
Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B




More information about the Qt-creator mailing list