[Bug preprocessor/58687] New: "#line __LINE__ ..." changes subsequent line numbers

mtewoodbury at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 11 03:47:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58687

            Bug ID: 58687
           Summary: "#line __LINE__ ..." changes subsequent line numbers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mtewoodbury at gmail dot com

A preprocessor directive of the form '#line __LINE__ ..." should NOT change the
line number.  That is '__LINE__' should evaluate to the number of the NEXT line
in this context.

If you read the standards carefully, __LINE__ should have a value equal to the
number of 'new line' characters seen by the phaee 1 translation plus one WHEN
THE SUBSTITUTION OCCURS (unless modified by previous #line directives).

When the subsituyion occurs is controlled by the parsing done in phase 4 of
translation.  Specifically, subsitution in preprocessing directives occure when
the specific form of the directive has been  formally identified AND that form
calls for <pp_token> aubstitution.  The form in this case is:

    '#' 'line' <pp_token>+ <new_line>

Note that the terminating <new line> token has to have been seen BEFORE the
form is identifiad.  That means __LINE__ will normally have the line number of
the NEXT line in the file when the substitution occurs.  FURTHER NOTE that any
<new line> tokens in comments will also have been counted when the substiturion
occurs.

What is apparently happening instead is that the substitution is being made
BEFORE the particular form of the '#line' directive has been completely and
formally identified.  In other wordds you have folded the translation phases
togeather and botched up the carefully structured procedure with its
intentional delays in substitution set forth in the standard.



More information about the Gcc-bugs mailing list