[Development] Using '#pragma once' instead of include guards?

Volker Hilsheimer volker.hilsheimer at qt.io
Wed Nov 2 15:48:50 CET 2022


> On 2 Nov 2022, at 15:25, Marc Mutz via Development <development at qt-project.org> wrote:
> 
> Hi Volker,
> 
> On 14.10.22 17:12, Volker Hilsheimer via Development wrote:
>> Anyway, I’ve added the respective text to the coding convention wiki 
>> page.
>> https://wiki.qt.io/Coding_Conventions
> 
> Having read the thread in total, I'm surprised about this outcome. 
> AFAIK, we haven't had problems with traditional include guards, yet, and 
> no compelling use-case for #pragma once was presented, so I don't see 
> why we're now allowing it. Esp. since the rule as written is more 
> complicated than "always use header guards".


The Qt Creator team is using '#pragma once', so does Qt Application Manager. Qt itself uses #pragma once in several places, e.g. in the qttools submodule, but also in a few qtbase tests.

I see no reason to push a convention down the throat of those teams that use it without problems today. The discussion here has given no reason to assume problems as long as usage is restricted to unexposed (ie non-SDK) headers.

Documenting that we must not use '#pragma once’ when there is a significant body of code that does seems counter-productive. It would not represent observable reality, which happens to be a bit more complicated than “we always use header guards, and if we don’t it’s a mistake”.

If anyone wants to convince e.g. the Qt Creator team to migrate away from '#pragma once’ for the sake of a simplified rules in our coding convention - well, best of luck ;)

Volker



More information about the Development mailing list