Bug 11569 - there's no substitute for #pragma once
Summary: there's no substitute for #pragma once
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 3.2.2
: P2 minor
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-18 09:33 UTC by Lawrence D'Oliveiro
Modified: 2003-07-29 22:29 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-29 22:09:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lawrence D'Oliveiro 2003-07-18 09:33:16 UTC
#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.
Comment 1 Andrew Pinski 2003-07-18 13:39:19 UTC
I think the problem is pragma once does not always work and that is why it is "obsolete".
Comment 2 Wolfgang Bangerth 2003-07-18 13:58:43 UTC
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.
Comment 3 Lawrence D'Oliveiro 2003-07-22 06:53:46 UTC
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?
Comment 4 Andrew Pinski 2003-07-22 11:49:07 UTC
The situations are with PCH (which is not in any released version yet).
Comment 5 Andrew Pinski 2003-07-22 13:58:33 UTC
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.
Comment 6 Wolfgang Bangerth 2003-07-22 14:00:02 UTC
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.
Comment 7 Lawrence D'Oliveiro 2003-07-23 04:37:34 UTC
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.
Comment 8 Lawrence D'Oliveiro 2003-07-23 04:54:01 UTC
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?
Comment 9 Wolfgang Bangerth 2003-07-23 14:21:29 UTC
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.
Comment 10 Neil Booth 2003-07-29 22:08:28 UTC
I'm handling this.
Comment 11 Neil Booth 2003-07-29 22:09:12 UTC
Mine.
Comment 12 Neil Booth 2003-07-29 22:29:09 UTC
#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.