From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20939 invoked by alias); 20 Apr 2002 22:16:09 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 20888 invoked by uid 71); 20 Apr 2002 22:16:05 -0000 Date: Sat, 20 Apr 2002 15:16:00 -0000 Message-ID: <20020420221605.20885.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Neil Booth Subject: Re: preprocessor/6386: Spurious "unterminated #if" Reply-To: Neil Booth X-SW-Source: 2002-04/txt/msg01056.txt.bz2 List-Id: The following reply was made to PR preprocessor/6386; it has been noted by GNATS. From: Neil Booth To: Andreas Schwab Cc: gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: preprocessor/6386: Spurious "unterminated #if" Date: Sat, 20 Apr 2002 23:08:34 +0100 Andreas Schwab wrote:- > #if 1 > #include "b.c" > #endif > $ cat b.c > S > $ gcc -E a.c > # 1 "a.c" > # 1 "" > # 1 "" > # 1 "a.c" > > > # 1 "b.c" 1 > S > # 4 "a.c" 2 > a.c:2:1: unterminated #if Thanks for the bug report. I'm testing this patch for regressions; if it passes I'll apply it to 3.1 and 3.2. Neil. * cppmacro.c (funlike_invocation_p): Don't step back over CPP_EOF. testsuite: * gcc.dg/cpp/endif.h, gcc.dg/cpp/endif.c: New tests. Index: cppmacro.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v retrieving revision 1.98 diff -u -p -r1.98 cppmacro.c --- cppmacro.c 14 Apr 2002 18:42:46 -0000 1.98 +++ cppmacro.c 20 Apr 2002 22:04:19 -0000 @@ -632,12 +632,15 @@ funlike_invocation_p (pfile, node) return collect_args (pfile, node); } - /* Back up. We may have skipped padding, in which case backing up - more than one token when expanding macros is in general too - difficult. We re-insert it in its own context. */ - _cpp_backup_tokens (pfile, 1); - if (padding) - push_token_context (pfile, NULL, padding, 1); + if (token->type != CPP_EOF) + { + /* Back up. We may have skipped padding, in which case backing + up more than one token when expanding macros is in general + too difficult. We re-insert it in its own context. */ + _cpp_backup_tokens (pfile, 1); + if (padding) + push_token_context (pfile, NULL, padding, 1); + } return NULL; } Index: testsuite/gcc.dg/cpp/endif.c =================================================================== RCS file: testsuite/gcc.dg/cpp/endif.c diff -N testsuite/gcc.dg/cpp/endif.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gcc.dg/cpp/endif.c 20 Apr 2002 22:04:19 -0000 @@ -0,0 +1,14 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Test case for PR preprocessor/6386 by Andreas Schwab. We'd back up + over the CPP_EOF token (indicating not a funlike macro invocation) + in the header file, which would then be passed through as a real + EOF, leading to an early exit (and therefore bogus complaint about + unterminated #if). */ + +#define S(x) +#if 1 +#include "endif.h" +#endif Index: testsuite/gcc.dg/cpp/endif.h =================================================================== RCS file: testsuite/gcc.dg/cpp/endif.h diff -N testsuite/gcc.dg/cpp/endif.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gcc.dg/cpp/endif.h 20 Apr 2002 22:04:19 -0000 @@ -0,0 +1 @@ +S