Using nullptr instead of Q_NULLPTR

Jarosław Staniek staniek at kde.org
Fri Aug 14 13:34:49 BST 2015


Sergio Martins wrote:

> 
https://community.kde.org/Frameworks/Policies#Frameworks_compiler_requirements_and_C.2B.2B11
> states gcc 4.5 as the minimum version, meaning we can't use nullptr.
> 
> However, since some time now, kf5 libraries are full of nullptr (~400
> occurrences) and nobody noticed.
> 
> We can either:
> - Bump the requirement to gcc 4.6 and allow nullptr
> - Fix kf5 and s/nullptr/Q_NULLPTR
> 
> 

Hi,
I found the the inconsistency in frameworks while thinking about adding some 
null pointer policy for some k*.git repos I maintain.

> I prefer the first option, it's the way forward and if someone was using
> an old gcc he would have complained by now.

This is a good point. This thread drifted in a direction of minimum compiler 
versions supported.
If I read the changelogs correctly msvc is like 8 years ahead of gcc (4.6) 
in this department. MSVC 2005 supported it already, this is enough for us I 
think.

Now in 2015 I propose to go with nullptr. Not using Q_NULLPTR removes on 
point against accepting Qt observed among 3rd-party folks: "Qt guys, like 
the EFL guys, like to invent everything from scratch". A tiny bit but 
always.

I also think we agree that anything other than 0 is good for readability and 
readability should be the priority.

Then, there's the consistency factor -- a reason to cover the topic of null 
pointers in the guide. I find neither Qt is consistent in what to use, Qt is 
not an example here then.

A patch for changing Q_NULLPTRs and NULLs is trivial to make but it's better 
to have it once and not doing further undos, otherwise the git-blame will be 
unnecessarily polluted. A patch for 0's would be a JJ.

In the worst case if someone calls us too modern, e.g for embedded projects, 
we'd be able a macro to ECM kdecompilersettings that defined nullptr back to 
0 (or is this already supported by cmake/etc.?)

Thoughts?

PS: A Krazy check checking for usage of NULLs and Q_NULLPTR would be lovely. 
Checking the use of 0's isn't easy, right?

Maybe I'll use pre-commit hook personally.

> 
> Btw, what are the c++98/c++11 requirements for applications ? I could only
> find the page for frameworks.
> 
> 
> Regards,
> --
> Sérgio Martins
-- 
regards, Jaroslaw Staniek

KDE:
: A world-wide network of software engineers, artists, writers, translators
: and facilitators committed to Free Software development - http://kde.org
Calligra Suite:
: A graphic art and office suite - http://calligra.org
Kexi:
: A visual database apps builder - http://calligra.org/kexi
Qt Certified Specialist:
: http://www.linkedin.com/in/jstaniek





More information about the kde-core-devel mailing list