This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Still a lot of C++ files getting "fixed"
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Still a lot of C++ files getting "fixed"
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Wed, 26 Jan 2000 11:12:28 -0800
- Cc: austern at sgi dot com, autogen at linuxbox dot com, gcc-bugs at gcc dot gnu dot org, mark at codesourcery dot com
- References: <200001261708.MAA25695@caip.rutgers.edu>
On Wed, Jan 26, 2000 at 12:08:49PM -0500, Kaveh R. Ghazi wrote:
> > From: Zack Weinberg <zack@wolery.cumb.org>
> >
> > > So it is not a great leap to do the same for -ansi. It can be
> > > pedantically ANSI for user code, and more relaxed about system
> > > headers, IMHO.
> >
> > If we're going to go down this road, we might consider also
> > disabling pedantic complaints about a token after #else/#endif in
> > the system headers. On SunOS, at least half the files modified
> > have only that change.
> > zw
>
> Sounds like a good idea.
>
> Are you volunteering to write a patch to cccp/cpplib? :-)
I'd be happy to :)
Here is a completely untested patch for tokens after #else/#endif.
I'll commit the cpplib half of it after testing. Who owns cccp?
The C++ comments issue will be trickier - it looks like we never emit
warnings for them, just recognize or don't recognize. That's wrong;
at the very least, C89 mode -pedantic needs to give warnings.
I need to think about what the appropriate behavior is.
zw
===================================================================
Index: cccp.c
--- cccp.c 2000/01/14 00:46:56 1.94
+++ cccp.c 2000/01/26 19:07:17
@@ -7842,7 +7842,7 @@ skip_if_group (ip, any, op)
break;
case T_ELSE:
case T_ENDIF:
- if (pedantic && if_stack != save_if_stack)
+ if (if_stack != save_if_stack)
validate_else (bp, endb);
case T_ELIF:
if (if_stack == instack[indepth].if_stack) {
@@ -7922,11 +7922,7 @@ do_else (buf, limit, op, keyword)
{
FILE_BUF *ip = &instack[indepth];
- if (pedantic) {
- SKIP_WHITE_SPACE (buf);
- if (buf != limit)
- pedwarn ("text following `#else' violates ANSI standard");
- }
+ validate_else (buf, limit);
if (if_stack == instack[indepth].if_stack) {
error ("`#else' not within a conditional");
@@ -7968,11 +7964,7 @@ do_endif (buf, limit, op, keyword)
FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{
- if (pedantic) {
- SKIP_WHITE_SPACE (buf);
- if (buf != limit)
- pedwarn ("text following `#endif' violates ANSI standard");
- }
+ validate_else (buf, limit);
if (if_stack == instack[indepth].if_stack)
error ("unbalanced `#endif'");
@@ -8020,16 +8012,18 @@ do_endif (buf, limit, op, keyword)
return 0;
}
-/* When an #else or #endif is found while skipping failed conditional,
- if -pedantic was specified, this is called to warn about text after
- the directive name. P points to the first char after the directive
- name. */
+/* Issue -pedantic warning for text which is not a comment following
+ an #else or #endif. Do not warn in system headers, as this is harmless
+ and very common on old systems. */
static void
validate_else (p, limit)
register const U_CHAR *p;
register const U_CHAR *limit;
{
+ if (!pedantic || instack[indepth].system_header_p)
+ return;
+
/* Advance P over whitespace and comments. */
while (1) {
while (*p == '\\' && p[1] == '\n')
===================================================================
Index: cpplib.c
--- cpplib.c 2000/01/19 23:47:13 1.99
+++ cpplib.c 2000/01/26 19:07:17
@@ -2008,7 +2008,7 @@ consider_directive_while_skipping (pfile
return 0;
case T_ELSE:
- if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
+ if (pfile->if_stack != stack)
validate_else (pfile, "#else");
/* fall through */
case T_ELIF:
@@ -2024,7 +2024,7 @@ consider_directive_while_skipping (pfile
}
case T_ENDIF:
- if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
+ if (pfile->if_stack != stack)
validate_else (pfile, "#endif");
if (pfile->if_stack == stack)
@@ -2140,8 +2140,7 @@ do_else (pfile, keyword)
{
cpp_buffer *ip = CPP_BUFFER (pfile);
- if (CPP_PEDANTIC (pfile))
- validate_else (pfile, "#else");
+ validate_else (pfile, "#else");
skip_rest_of_line (pfile);
if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
@@ -2180,8 +2179,7 @@ do_endif (pfile, keyword)
cpp_reader *pfile;
const struct directive *keyword ATTRIBUTE_UNUSED;
{
- if (CPP_PEDANTIC (pfile))
- validate_else (pfile, "#endif");
+ validate_else (pfile, "#endif");
skip_rest_of_line (pfile);
if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
@@ -2226,19 +2224,20 @@ do_endif (pfile, keyword)
return 0;
}
-/* When an #else or #endif is found while skipping failed conditional,
- if -pedantic was specified, this is called to warn about text after
- the command name. P points to the first char after the command name. */
+/* Issue -pedantic warning for text which is not a comment following
+ an #else or #endif. Do not warn in system headers, as this is harmless
+ and very common on old systems. */
static void
validate_else (pfile, directive)
cpp_reader *pfile;
const char *directive;
{
- int c;
+ if (! CPP_PEDANTIC (pfile) || CPP_BUFFER (pfile)->system_header_p)
+ return;
+
cpp_skip_hspace (pfile);
- c = PEEKC ();
- if (c != EOF && c != '\n')
+ if (PEEKC () != '\n')
cpp_pedwarn (pfile,
"text following `%s' violates ANSI standard", directive);
}