bool avoid_paste;
bool do_line_adjustments;
bool in_pragma;
- bool line_marker_emitted;
public:
token_streamer (cpp_reader *pfile)
:avoid_paste (false),
do_line_adjustments (cpp_get_options (pfile)->lang != CLK_ASM
&& !flag_no_line_commands),
- in_pragma (false),
- line_marker_emitted (false)
+ in_pragma (false)
{
gcc_assert (!print.streamer);
print.streamer = this;
if (token->type == CPP_EOF)
return;
+ /* Keep track when we move into and out of system locations. */
+ const bool is_system_token = in_system_header_at (loc);
+ const bool system_state_changed
+ = (is_system_token != print.prev_was_system_token);
+ print.prev_was_system_token = is_system_token;
+
/* Subtle logic to output a space if and only if necessary. */
+ bool line_marker_emitted = false;
if (avoid_paste)
{
unsigned src_line = LOCATION_LINE (loc);
if (do_line_adjustments
&& !in_pragma
&& !line_marker_emitted
- && print.prev_was_system_token != !!in_system_header_at (loc)
+ && system_state_changed
&& !is_location_from_builtin_token (loc))
/* The system-ness of this token is different from the one of
the previous token. Let's emit a line change to mark the
new system-ness before we emit the token. */
{
- do_line_change (pfile, token, loc, false);
- print.prev_was_system_token = !!in_system_header_at (loc);
+ line_marker_emitted = do_line_change (pfile, token, loc, false);
}
if (!in_pragma || should_output_pragmas ())
{
cpp_output_token (token, print.outf);
- line_marker_emitted = false;
print.printed = true;
}
}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-save-temps -Wint-conversion" } */
+#include "pr60014-3.h"
+
+/* The line continuation on the next line is what triggers the problem here,
+ because it synchronizes the output line between the input source and the
+ preprocessed output (whereas without the line continuation, the
+ preprocessed output would be off by one line from having output a #pragma
+ on a line by itself). Therefore, the token streamer doesn't have a reason
+ to generate a line marker purely based on the line number. That gives it
+ the chance to consider whether instead it needs to generate a line marker
+ based on a change of the "in-system-header" state, allowing us to test that
+ it comes to the right conclusion, which it did not, prior to this commit to
+ resolve PR60014. */
+P(GCC diagnostic) \
+const char *should_warn = 1; /* { dg-warning {-Wint-conversion} } */