gnu/gcc/e1c8dac7ca8dde4d99776685dee43e05cd3ea6d2 libcpp: Use -1 for closed header-unit fd [PR c++/127097]
_cpp_find_header_unit closes the source descriptor after resolving a
header unit, but records zero instead of the established -1 sentinel.
A later textual include through an alternate pathname therefore skips
reopening the source and reads stdin. Descriptor zero is also a valid
result from open when stdin was previously closed.
Close every valid descriptor and restore -1. Add a module regression
that imports a header unit and includes the same file through an
alternate spelling.
Assisted-by: Claude Opus 5 (Anthropic)
libcpp/
PR c++/127097
* files.cc (_cpp_find_header_unit): Close descriptor zero and set
the closed descriptor sentinel to -1.
gcc/testsuite/
PR c++/127097
* g++.dg/modules/pragma-once-hu-1_a.H: New test.
* g++.dg/modules/pragma-once-hu-1_b.C: New test.
Signed-off-by: Alexey Klimkin <alexey.klimkin@intel.com>
3 files changed