[Bug c++/90126] gcc can not correctly deal with its own preprocessed output
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90126 Richard Biener changed: What|Removed |Added Keywords||diagnostic Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Richard Biener --- Confirmed. I think this is odd behavior of the warning (not sure what it is about). Note you get no warning when you pass -fpreprocessed. The key to the diagnostic is that the anonymous namespace appears in a file (through a #line directive) that is not the same as the file compiled. Thus, the following testcase warns: # 1 "t.C" namespace { struct Receiver { int object; }; } struct Node { Receiver receiverQueue; Node() { } }; int main(int argc, char* argv[]) { return 0; } > g++ t2.C note to put the testcase into a file named t2.C, it doesn't warn when the filename is t.C. This is because the warning intends to warn about anonymous namespaces in headers which, when included from multiple sources may cause issues. So I think this behaves as intended and you need to compile preprocessed source with -fpreprocessed (or use t2.ii filenames) or retain the original filename. Or disable this particular warning.
[Bug c++/90126] gcc can not correctly deal with its own preprocessed output
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90126 --- Comment #2 from Jonathan Wakely --- tl;dr the preprocessor should only be used once. You're running it twice on the same input.
[Bug c++/90126] gcc can not correctly deal with its own preprocessed output
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90126 --- Comment #1 from Jonathan Wakely --- I don't think this is a bug. If you tell gcc that the preprocessed output is preprocessed output, then the behaviour is consistent. So either: g++ -E namespace_anonymous_1_min_ok.cpp > temp_namespace_anonymous.ii g++ temp_namespace_anonymous.ii Or: g++ -E namespace_anonymous_1_min_ok.cpp > temp_namespace_anonymous.cpp g++ -x c++-cpp-output temp_namespace_anonymous.cpp The warning is suppressed when the type is defined in the "main input context" i.e. not in a header file. When you treat the preprocessed output as unpreprocessed source you end up with two sets of line markers, which makes GCC think the type is defined in a header. If you want to use preprocessed output this way you should probably generate it without line markers: g++ -E -P namespace_anonymous_1_min_ok.cpp > temp_namespace_anonymous.cpp g++ temp_namespace_anonymous.cpp