]> git.ipfire.org Git - thirdparty/gcc.git/commit
libcpp: Fix up cpp_maybe_module_directive [PR120845]
authorJakub Jelinek <jakub@redhat.com>
Sun, 3 Aug 2025 16:27:42 +0000 (18:27 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sun, 3 Aug 2025 16:27:42 +0000 (18:27 +0200)
commita68f416a706bc61bb323773295189c4ea413ffd6
tree6b6865fb4c0705d7430c2ceddf0c66a67df33a6a
parent5ecbe70d0f34ac9dadefc21c809fb6a2369d1bad
libcpp: Fix up cpp_maybe_module_directive [PR120845]

My changes for "Module Declarations Shouldn’t be Macros" paper broke
the following testcase.  The backup handling intentionally tries to
drop CPP_PRAGMA_EOL token if things go wrong, which is desirable for the
case where we haven't committed to the module preprocessing directive
(i.e. changed the first token to the magic one).  In that case there is
no preprocessing directive start and so CPP_PRAGMA_EOL would be wrong.
If there is a premature new-line after we've changed the first token though,
we shouldn't drop CPP_PRAGMA_EOL, because otherwise we ICE in the FE.

While clang++ and MSVC accept the testcase, in my reading it is incorrect
at least in the C++23 and newer wordings and I think the changes have been
a DR, https://eel.is/c++draft/cpp.module has no exception for new-lines
and https://eel.is/c++draft/cpp.pre#1.sentence-2 says that new-line (unless
deleted during phase 2 when after backslash)  ends the preprocessing
directive.

The patch arranges for eol being set only in the not_module case.

2025-08-03  Jakub Jelinek  <jakub@redhat.com>

PR c++/120845
libcpp/
* lex.cc (cpp_maybe_module_directive): Move eol variable declaration
to the start of the function, initialize to false and only set it to
peek->type == CPP_PRAGMA_EOL in the not_module case.  Formatting fix.
gcc/testsuite/
* g++.dg/modules/cpp-21.C: New test.
gcc/testsuite/g++.dg/modules/cpp-21.C [new file with mode: 0644]
libcpp/lex.cc