public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "joseph at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/58687] "#line __LINE__ ..." changes subsequent line numbers
Date: Fri, 29 Nov 2013 16:57:00 -0000	[thread overview]
Message-ID: <bug-58687-4-j66Xg0bE7m@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-58687-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #22 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Fri, 29 Nov 2013, mtewoodbury at gmail dot com wrote:

> The elaborate description of the different forms of the '#line' (and other) 
> directives makes it clear that <pp-token> expansion is not to take place until 
> after the <end-of-line> for the directive has been seen.  

The question is not when it takes place, it's what the "current token" is 
when it takes place, because "line number" is defined in terms of the 
current token rather than the time of expansion.  I think the current 
token is clearly __LINE__ on the #line directive.  Consider the case where 
there are no more tokens after that directive, just the newline at the end 
of the directive (you can easily construct cases where the value of 
__LINE__ in such a context affects the validity of the program, by 
concatenating it with something else to form what might or might not be a 
macro name) - it's not possible the the current token to be anything on a 
subsequent line, because there aren't any subsequent tokens.  So the 
current token has got to be __LINE__ (or maybe, in the more complicated 
cases I referred to, something else on the #line line).  That's different 
from

macro
(
__LINE__
)

where all of the tokens from "macro" to ")" are involved in expansion at 
the same time and you can argue for any of "macro", "__LINE__" and ")" as 
being the "current token".  (It's also different from the cases where 
backslash-newline appears in the middle of __LINE__ so the question is 
whether "to the current token" means to the start of end of that token.)

> Accepted usage is for '#line __LINE__' to leave the line numbering unchanged.  

It's quite possible there's a common bug among multiple other 
implementations where it does leave the line number unchanged, but I'm now 
tending to that actually being a bug in those implementations rather than 
an ambiguity in the standard.  That is, there is no way in the standard to 
leave the line number unchanged, and no defect, and it might be better to 
wait until a revision process for a new major C standard version is 
underway them submit a proposal for e.g. #line with just a filename and no 
line number (or a #file directive - either would be a reasonable way of 
achieving that goal).


  parent reply	other threads:[~2013-11-29 16:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-11  3:47 [Bug preprocessor/58687] New: " mtewoodbury at gmail dot com
2013-10-23  7:16 ` [Bug preprocessor/58687] " mtewoodbury at gmail dot com
2013-10-25 19:01 ` mtewoodbury at gmail dot com
2013-10-25 22:56 ` mtewoodbury at gmail dot com
2013-10-26 13:39 ` mtewoodbury at gmail dot com
2013-10-26 21:15 ` pinskia at gcc dot gnu.org
2013-10-27 13:59 ` mtewoodbury at gmail dot com
2013-10-28 17:51 ` mtewoodbury at gmail dot com
2013-10-28 18:53 ` joseph at codesourcery dot com
2013-10-30  7:39 ` mtewoodbury at gmail dot com
2013-10-30 15:08 ` manu at gcc dot gnu.org
2013-10-30 17:59 ` mtewoodbury at gmail dot com
2013-10-30 18:13 ` joseph at codesourcery dot com
2013-10-30 19:43 ` mtewoodbury at gmail dot com
2013-10-31 18:00 ` mtewoodbury at gmail dot com
2013-11-04 14:14 ` mtewoodbury at gmail dot com
2013-11-04 18:18 ` joseph at codesourcery dot com
2013-11-19 16:08 ` mtewoodbury at gmail dot com
2013-11-19 16:37 ` joseph at codesourcery dot com
2013-11-28 22:52 ` jsm28 at gcc dot gnu.org
2013-11-29  4:52 ` mtewoodbury at gmail dot com
2013-11-29 16:57 ` joseph at codesourcery dot com [this message]
2013-11-29 22:49 ` mtewoodbury at gmail dot com
2013-11-30  0:04 ` joseph at codesourcery dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-58687-4-j66Xg0bE7m@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).