#pragma once used in a .h file indicates that it is only to be parsed once, even if it is (directly or indirectly) included multiple times in the same source file. However, every time you use this pragma, you get a warning saying it is "obsolete", and there seems to be no compiler option to turnoff this warning. I believe there is some kind of recommendation that one should bracket the contents of the .h file with something like #ifndef _SOME_ARBITRARY_SYMBOL_CONSTRUCTED_FROM_FILE_NAME_ #define _SOME_ARBITRARY_SYMBOL_CONSTRUCTED_FROM_FILE_NAME_ ... #endif and gcc will "do the right thing". Now, "doing the right thing" is all very well where it saves you doing extra work, but where it makes you go out of your way to write something much more verbose than the obvious thing, as in this case, it just seems to me to be brain-dead. Conclusion: please provide some way to turn off the warning about #pragma once being "obsolete". Thank you.
I think the problem is pragma once does not always work and that is why it is "obsolete".
Pragma once is obsoleted, in other words it will be removed in the next version anyway. The warning will then become a hard error, so providing a flag now that suppresses the warning seems pointless. W.
Wolfgang Bangerth wrote: >Pragma once is obsoleted, in other words it will be removed in the next >version anyway. Why is it being removed? Andrew Pinski wrote: >I think the problem is pragma once does not always work and that >is why it is "obsolete". Under what situations might it fail to work?
The situations are with PCH (which is not in any released version yet).
Actually for 3.4 the switch to turn off the warning is -Wno-deprecated, so this is already fixed but since #pragma once is going away, I am going to close this as invalid.
Regarding the reasons for removing the features: there have been long discussions on the gcc mailing lists about this. I'm not familiar with the details, but a web search on the mailing lists should turn up quite some information. W.
Andrew Pinski wrote: >>Under what situations might it fail to work? >The situations are with PCH (which is not in any released version yet). I'm not surprised PCH is not in any released version yet. You will never get it to work reliably, for reasons that have nothing to do with #pragma once. It's been tried on other platforms for many years, and it invariably ends up being more trouble than the problem it's trying to solve. I speak from experience.
Wolfgang Bangerth wrote: >Regarding the reasons for removing the features: there have been long >discussions on the gcc mailing lists about this. Yes, I have come across archives of such discussions. Let me summarize the points: 1) Possible inconsistencies in pragma semantics between different compilers ("pragmas are a bad idea in general"). 2) Not an official standard supported by all compilers. Well, I've got news for you. In the years since those discussions, #pragma once has become quite a widely supported feature, available on many compilers on many platforms. Essentially, it is now a de-facto standard, like it or not. Sure, there are technical reasons why it's a bad idea, but that doesn't make any difference to the fact that it is widely used. If you don't support it, then you put yet another obstacle in the path of those trying to port code from other platforms. I can't claim that GCC isn't big enough to be a law unto itself if it wants to, in true Microsoft style. Do you want to be like that, or do you want to be a team player, mindful of the needs of those who have to cope with code running on multiple platforms using multiple compilers?
Your case is not helped if you insult those who have put time and thought into the problem by accusing them of arrogant behavior. Secondly, gcc is by and large a volunteer project. If you want to see a feature working and supported, feel free to offer patches -- these are the rules by which gcc works. W.
I'm handling this.
Mine.
#pragma once has been undeprecated in 3.4 because it contains a correct implementation at last. The problems with #pragma once have been related to filename semantics and symlinks / hardlinks etc. I will soon undeprecate in 3.3, though its implementation will never be fixed.