make -j and #pragma GCC diagnostic

Viewed 29

Let's say I add the following to A.cpp

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
<code with unused parameters here>
#pragma GCC diagnostic pop

Then I build with "make -j." If "A.cpp" and "some_other_file_with_no_pragma.cpp" get built in parallel, will the #pragma above apply to both files? I would think not, but can't find a definitive answer.

2 Answers

Not unless you are doing some really weird stuff in your Makefile.

Compiler compiles each translation unit(.cpp+included .hpp) independently, meaning each pragma only applies to this one translation unit.

Running make -jN will execute N rules in parallel, each (line) in a separate shell process. Resulting in up to N parallel compilers which will not interfere with each other.

… will the #pragma above apply to both files?

No. From the documentation (bold emphasis mine):

Note that these pragmas override any command-line options. GCC keeps track of the location of each pragma, and issues diagnostics according to the state as of that point in the source file. Thus, pragmas occurring after a line do not affect diagnostics caused by that line.

Related