[Qt-creator] Use #pragma once as default instead of header guards

Milian Wolff mail at milianw.de
Wed Jan 13 16:23:51 CET 2016


On Mittwoch, 13. Januar 2016 15:22:38 CET Nikolai Kosjar wrote:
> On 01/13/2016 01:52 PM, Joerg Bornemann wrote:
> > Still, as it came up, this argument raises the interesting question what
> > will happen to users of the clang code model that cannot switch to
> > (non-standard) pragma once for this or that reason?
> > 
> > What would it take to fix this problem? Can we work around it? Can we
> > provide an upstream fix?
> 
> A fix from Erik is pending for review at http://reviews.llvm.org/D15994
> , but so far there were no comments.
> 
> > Apart from that, I did not understand the problem at all.
> > The opening #ifndef does match the #endif, doesn't it?
> > If "matches" means "is balanced with" at least.
> 
> As far as I understand:
> 
> The preamble includes everything up to the very first declaration (not
> including it). Now the rule seems to be that a preamble is only
> generated if the preprocessor conditions are balanced *within* the
> preamble. In the given example #ifndef is in the preamble region, but
> not #endif.

If I understand correctly now, this could only happen if you try to parse the 
header as a translation unit, which it isn't. If you have a .cpp including 
that header, the #ifndef + #endif is balanced and no issues arise - or?

In KDevelop we do that - we try to find the translation unit entry point for a 
header and use that instead of the header file directly. This fixed a huge 
amount of bugs for us, also outside of the preamble afaik. Furthermore, this 
is what you usually want anyways as you then automatically update the state of 
the .cpp file as well. Furthermore, you can parse "broken" headers that way 
which depend on the include stack/state that came before it in the .cpp file.

If you don't do that already, I can only recommend you to do something like 
that.

Cheers

-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20160113/3ad951e0/attachment.sig>


More information about the Qt-creator mailing list