This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: preprocessor/7962: -traditional's handling of unbalanced " in unused #if blocks


The following reply was made to PR preprocessor/7962; it has been noted by GNATS.

From: Zack Weinberg <zack@codesourcery.com>
To: mrs@apple.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: preprocessor/7962: -traditional's handling of unbalanced " in unused #if blocks
Date: Tue, 17 Sep 2002 23:17:50 -0700

 On Wed, Sep 18, 2002 at 05:46:52AM -0000, mrs@apple.com wrote: 
 
 > If one compiles the enclosed file with -traditional-cpp, the program
 > will return with 1, if compiled with the other cpp, it returns 0, the
 > correct value.  To understand why, examine the output of -E between
 > the two and look for case 1:
 > 
 > ash-2.05a$ gcc t3.c -traditional-cpp -E | grep case
 > t3.c:15:40: warning: multi-line string literals are deprecated
 >   case 0:
 >   case 2:
 > bash-2.05a$ gcc t3.c -E | grep case
 > case 0 : 
 > case 1 : 
 > case 2 : 
 
 Odd; my testing indicates precisely the opposite effect, with both
 2.95 and 3.2.
 
 $ gcc-2.95 -traditional-cpp -E test.c | grep case
   case 0:
   case 1:
   case 2:
 $ gcc-2.95 -E test.c | grep case
   case 0:
   case 2:
 
 $ gcc-3.2 -traditional-cpp -E test.c | grep case
   case 0:
   case 1:
   case 2:
 $ gcc-3.2 -E test.c | grep case
 test.c:15:40: warning: multi-line string literals are deprecated
 test.c:22:8: warning: extra tokens at end of #endif directive
 test.c:28:8: warning: extra tokens at end of #endif directive
   case 0:
   case 2:
 
 In 3.3 all the case statements survive in both modes, but the
 translation unit is rejected without -traditional-cpp.
 
 $ ./xgcc -B./ -traditional-cpp -E test.c | grep case
 test.c:16: warning: extra tokens at end of #endif directive
 test.c:22: warning: extra tokens at end of #endif directive
 test.c:28: warning: extra tokens at end of #endif directive
   case 0:
   case 1:
   case 2:
 
 $ ./xgcc -B./ -E test.c | grep case
 test.c:15:40: missing terminating " character
 test.c:16:8: warning: extra tokens at end of #endif directive
 test.c:21:40: missing terminating " character
 test.c:22:8: warning: extra tokens at end of #endif directive
 test.c:28:8: warning: extra tokens at end of #endif directive
   case 0:
   case 1:
   case 2:
 
 The reason for the effect as I see it is quite clear - up to 2.2,
 multiline strings exist, so everything from the first panic() to the
 second, including the first #endif, the missing case statement, and
 the next #if NOCOPY, is absorbed into the string constant.  The entire
 thing is then thrown away because it's inside a failed conditional
 block (extending from the first #if NOCOPY to the _second_ #endif).
 
 In traditional mode, however, strings silently end at the end of the
 line ("a workaround for not knowing comment boundaries when
 -traditional is used to preprocess things which are not C", to
 paraphrase the manual) so all three #endif-s are honored.  And in 3.3,
 there are no multiline strings, so the same thing happens without
 -traditional-cpp.
 
 I don't see how you got the effect you described, nor do I see what
 you want changed.  Please clarify.
 
 zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]