[Bug c++/127097] [modules] Alternate include of a header unit reads stdin
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Sep 1 14:53:22 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127097
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:e1c8dac7ca8dde4d99776685dee43e05cd3ea6d2
commit r17-3819-ge1c8dac7ca8dde4d99776685dee43e05cd3ea6d2
Author: Alexey Klimkin <alexey.klimkin@intel.com>
Date: Tue Aug 25 20:36:48 2026 -0700
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>
More information about the Gcc-bugs
mailing list