https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60014
Lewis Hyatt <lhyatt at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lhyatt at gcc dot gnu.org --- Comment #8 from Lewis Hyatt <lhyatt at gcc dot gnu.org> --- The testcase for this PR was one of many that got fixed by r9-1926 (for PR69558). The location of the token resulting from expanding the builtin macro __LINE__ was, prior to r9-1926, pointing to the closing paren of the macro invocation, i.e. not in the system header. After r9-1926, the location of the token is a virtual location encoding that the token resulted from expansion of a macro defined in a system header, and so the "system"-ness of the token no longer gets lost. Fredrik's original testcase is a nice one. Every element in it is essential to reveal the issue, including the extra semicolon in the FOO macro and the newline in the invocation. Although that testcase now works correctly, Manuel's point still stands, c-ppoutput.cc should not have behaved this way, even absent r9-1926. The problem is that here: ====== if (do_line_adjustments && !in_pragma && !line_marker_emitted && print.prev_was_system_token != !!in_system_header_at (loc) && !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); } ======= print.prev_was_system_token should be set always, not only when the if statement is reached and evaluates to true. In this PR's testcase prior to r9-1926, the check evaluated to false when streaming the semicolon from the macro expansion, because a line marker had been printed due to the fact that the __LINE__ token and the semicolon were assigned locations on different lines. So the logic in c-ppoutput.cc assumes that you can never get two tokens on different lines without a line change callback, which is not a crazy assumption but was violated due to the issue fixed by r9-1926. However, there are other code paths besides the line change logic that can trigger the same issue still now. One way is to stream a deferred CPP_PRAGMA token, since that code path doesn't even execute the above if statement. As of r13-1544, we do see such tokens while preprocessing, so here is a modified testcase that fails on master: ====== $ cat t2.h #pragma GCC system_header #define X _Pragma("GCC diagnostic push"); $ cat t2.c #include "./t2.h" X const char* should_warn = 1; $ gcc -Wint-conversion -c t2.c t2.c:3:27: warning: initialization of ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 3 | const char* should_warn = 1; | ^ $ gcc -Wint-conversion -c t2.c -save-temps $ ====== I can test the fix and prepare a patch for that.