The problem here is with deferred pragmas, libcpp would inject a PRAGMA_EOL before the end of the new line in the tokens stream but traditional cpp path does not use that path except when dealing with directives. In this case we call out to handle `#if` directive and that token got added due to the change of line #. So at the end of a directive, we need to set in_deferred_pragma to false as traditional cpp path handles the new line itself.
Bootstrapped and tested on x86_64-linux. PR preprocessor/79516 libcpp/ChangeLog: * directives.cc (end_directive): Also set in_deferred_pragma to false with traditional cpp. gcc/testsuite/ChangeLog: * c-c++-common/cpp/pragma-message-trad.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> --- gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c | 9 +++++++++ libcpp/directives.cc | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c diff --git a/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c b/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c new file mode 100644 index 00000000000..0478e6fc7c7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pragma-message-trad.c @@ -0,0 +1,9 @@ +/* { dg-do preprocess } */ +/* { dg-options "-traditional-cpp" } */ +/* PR preprocessor/79516 */ + +#pragma message "OK" + +#if 0 +#pragma message ("Not printed") +#endif diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 6b0d691f491..9c0f77ab017 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -323,6 +323,8 @@ end_directive (cpp_reader *pfile, int skip_line) /* Revert change of prepare_directive_trad. */ if (!pfile->state.in_deferred_pragma) pfile->state.prevent_expansion--; + /* No longer inside a deferred pragma. */ + pfile->state.in_deferred_pragma = false; if (pfile->directive != &dtable[T_DEFINE]) _cpp_remove_overlay (pfile); -- 2.43.0