https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125964
Bug ID: 125964
Summary: Misleading info in "Using Precompiled Headers" article
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: web
Assignee: unassigned at gcc dot gnu.org
Reporter: nikita.leontiev at gmail dot com
Target Milestone: ---
Project includes precompiled header (pch.h) and a source that uses PCH. Both in
src dir.
Goal: use "build" dir for all objects.
https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html states:
"Alternatively, you might decide to put the precompiled header file in a
directory and use -I to ensure that directory is searched before (or instead
of) the directory containing the original header."
With -I, PCH will only be used if included as system header (#include <pch.h>),
otherwise local dir will be first in lookup order and pch.h will be used
instead.
Documentation doesn't inform that system include form is mandatory here. In the
previous paragraph, quote include form is given as an example:
"For instance, if you have #include "all.h", and you have all.h.gch in the same
directory as all.h, then the precompiled header file is used if possible, and
the original header is used otherwise."
Including PCH as a system header is a bad practice, so the only possible
solution is to use -include, which is described in the following documentation
paragraph.