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

Marc Mutz marc.mutz at qt.io
Wed Nov 2 15:25:25 CET 2022


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".

If and when we decide that we have an include guards problem, it was 
said that clang-tidy has a header guard normalizer, so it would be easy 
to just run it and use something like

   QT_GUARD_INCLUDE_OF_<module>_<subdir>_<header>

Example:

   QT_GUARD_INCLUDE_OF_QTCORE_IO_QIODEVICE_H

which no-one wants to have to type, but would be trivial for a tool to 
produce.

Thanks,
Marc



More information about the Development mailing list