From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23217 invoked by alias); 25 Oct 2013 19:01:16 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23182 invoked by uid 48); 25 Oct 2013 19:01:12 -0000 From: "mtewoodbury at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug preprocessor/58687] "#line __LINE__ ..." changes subsequent line numbers Date: Fri, 25 Oct 2013 19:01:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: preprocessor X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mtewoodbury at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-10/txt/msg01897.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58687 Max TenEyck Woodbury changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mtewoodbury at gmail dot com --- Comment #2 from Max TenEyck Woodbury --- Grumble! Modified testsuite/gcc.dg/cpp/line4.c to test __LINE__ use. I think I saw a stronger set of tests while 'googling' the problem. I was a bit short on understanding when I saw it, so I didn't mark it for study... I've looked at the code that handles this. It's in the libcpp tree. Thw indentation is messed up. '\t' used in many places WITHOUT consistant tab widths. I see spots with '\t' stops at 4 and at 8. Indent width is mostly 2. Style is a bit mixed. FOR MY OWN USE, I've cleaned this up. The result is much more readable. I tried a simple look-ahead hack, but no go. Going the mild KLUGE route: Use a special value to indicate the bad value and emit it under special circumstances. - define the special value CUR__LINE__ in include/libcpp.h (-1) - modify state.in_directive to have a special value (2) when in the #line directive (in do_line). - check for the CUR__LINE__ value at the end of do_line after flushing the tokens and use replace the special value with the current line number before doing the state change. - in macro.c, __LINE__ processing, look for the special stat.in_directive value and return CUR__LINE__ if it has the special value. Potential problem if someone uses __LINE__ to construct the file name. Intrest?