[Development] C++11 for Examples

Thiago Macieira thiago.macieira at intel.com
Mon Mar 2 21:25:45 CET 2015

On Monday 02 March 2015 16:20:29 Blasche Alexander wrote:
> The suggestion was/is to permit the usage of C++11 in Qt examples. Here is a
> concrete set of suggestions to address the open issues and consequences:
> 1.) Use C++11 for examples starting with Qt 5.6

I'd say "use C++11 where it makes for cleaner code".

Don't go using things you don't have to just because they're there.

> 2.) Coding convention for C++11 constructs and set of permitted features:
> https://wiki.qt.io/index.php?title=Coding_Conventions#Conventions_for_C.2B.2
> B11_usage

I didn't know this existed. That's a nice summary and a good start.

I guess we'll expand it as necessary.

> 3.) The coding conventions above imply a set of base line compilers for Qt
> examples (gcc 4.5+, VS2010+, OSX 10.7+)

10.7 is gone for Qt 5.5, so we only need for XCode 5 and up.

> 4.) Don't use any of the macros such as Q_DECL_OVERRIDE (assuming that
> override would be part of the accepted set of features). The examples
> should be clean C++11 code.

Agreed, if we're going to write C++11 code to teach people, we should use the 
actual  keywords, not the Qt replacement.

> The suggestions 2 & 3 above are based on current Qt Creator policy.
> You might ask why just lambda and auto as suggestion? The biggest problem is
> that various compilers have differing support for C++11. Therefore each new
> C++11 feature is likely to enforce even stricter/newer example compilers.
> If you want your pet C++11 feature please ensure that the compilers in item
> 3 support this feature. Alternatively we may discuss whether the suggested
> list of "example base line" compilers is correct.

I'd say we should think of raising the bar a little. How about making the 
examples require GCC 4.7 and VS 2012? Those are 4-year-old compilers by the 
time Qt 5.6 is released.

Also, I don't expect us to do a wholesale replacement, so some examples should 
still work for a while in older compilers.

The common subset of features supported by GCC 4.7, VS 2012 and Clang 3.3 
(should match Apple Clang 5.0) is exactly VS2012.


Of those, atomics and extern templates should not happen in example code. As 
for rvalue refs, while they will work, std::move will be a problem for QNX.

> contains(QT_CONFIG, c++11)
> is a very coarse qmake check for a given set of C++11 features it is
> unlikely to be useful to serve as enabler for converted examples.
> Workarounds might be to not compile examples on unsupported platforms in
> the CI anymore or we define a new qmake flag that precisely covers the
> required set of C++ features. The latter would certainly be more user
> friendly.
> Comments, suggestions and desires?

Make it unconditional and let people disable with -nomake tests or 
-no-compile-examples if they have older compilers.

I'd also propose dropping the VS 2010 packages for either 5.5 or 5.6 and 
replace them with VS 2015.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Development mailing list