[Bug c++/89808] New: Disable "#pragma once in main file"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808 Bug ID: 89808 Summary: Disable "#pragma once in main file" Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: s_gcc_bugzilla at binarez dot com Target Milestone: --- I am building an environnement to execute c++ code and I do need to use #pragma once in my main cpp source code (and all cpp files actually). When I compile, I get the "#pragma once in main file" warning. The only way to turn this warning off is to disable all warnings with the -w option. I want to only disable this specific warning and keep all the other ones. gcc needs something like clang's -Wno-pragma-once-outside-header option. I do appreciate that this warning is actually useful but there are corner cases where this warning must be disabled.
[Bug preprocessor/89808] An option to disable warning "#pragma once in main file"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808 --- Comment #3 from sduguay --- (In reply to Richard Biener from comment #1) > Testcase: > > #pragma once > int main() {} > > > g++ t.C -S > t.C:1:9: warning: #pragma once in main file > #pragma once > ^~~~ > > > you could work around this by wrapping the pragma in a preprocessor > conditional Hi, thanks for adding a minimal test case. I tried: #if 1 #pragma once #endif but I'm still getting the warning.
[Bug preprocessor/89808] An option to disable warning "#pragma once in main file"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808 --- Comment #4 from sduguay --- (In reply to Jakub Jelinek from comment #2) > You haven't explained why do you need to use #pragma once in the main cpp > source file, are you sometimes including it as a header and other times > compiling it as the TU itself? Not to mention that it is best not to use > #pragma once at all anywhere. Yes, in the system I'm working on, there is no "main file", all C++ (xcpp files actually) are small C++ programs that I link with a generated main file. xcpp programs can use other programs (xcpp files) or libs (xhpp files). This is all working pretty well right now, except for that #pragma once warning. It's still under pretty heavy development. You can try it @ https://github.com/binarez/xcpp Thanks
[Bug preprocessor/89808] An option to disable warning "#pragma once in main file"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808 --- Comment #8 from sduguay --- (In reply to Jonathan Wakely from comment #6) > In any case, I agree with confirming this as a bug: all warnings should be > controllable by a -Wxxx option. > > Adding such an option is quite easy, and a good first contribution to GCC. > For an example of adding a new option see https://gcc.gnu.org/r192968 I was going to propose looking into it. I'll try to find some time.