This is the mail archive of the gcc-patches@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]

Patch: PR preprocessor/22168


This patch fixes PR preprocessor/22168.

GCC documents its '#assert' extension as deprecated.  However, it does
not ever warn if this extension is used.

This patch changes cpp to warn if the assertion feature is used.  It
will warn either in response to -Wdeprecated, or if -pedantic.  In
case both warnings are enabled I chose to make -pedantic take
precedence.  cpp will now also warn for other deprecated extensions if
-Wdeprecated is given.

Note that before this patch, cpp never used its 'warn_deprecated'
flag.  In order to reduce the impact of this addition, I changed this
warning to default to off.

Also, I changed c.opt to allow -Wdeprecated for C code.  Without this
there is no way to get warnings about assertions without using
-pedantic.

I discovered while writing this that -Wdeprecated doesn't seem to be
documented.

Bootstrapped and regression tested on x86 FC6.  There's new test
cases, and I had to modify one test case so that we don't pass
-pedantic-errors.

Ok?

Tom

:ADDPATCH preprocessor:

libcpp
2006-12-29  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/22168:
	* expr.c (eval_token): Warn for use of assertions.
	* directives.c (directive_diagnostics): Warn about extensions.
	* init.c (cpp_create_reader): Disable warn_deprecated by default.

gcc
2006-12-29  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/22168:
	* c.opt (Wdeprecated): Enable for C.

gcc/testsuite
2006-12-29  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/22168:
	* gcc.dg/cpp/assert4.c: Compile with -ansi and not -pedantic.
	* gcc.dg/cpp/pr22168.c: New file.
	* gcc.dg/cpp/pr22168-2.c: New file.

Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 120244)
+++ libcpp/expr.c	(working copy)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004 Free Software Foundation.
+   2002, 2004, 2006 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -607,10 +607,25 @@
 	}
       break;
 
-    default: /* CPP_HASH */
+    case CPP_HASH:
+      if (!pfile->state.skipping)
+	{
+	  /* A pedantic warning takes precedence over a deprecated
+	     warning here.  */
+	  if (CPP_PEDANTIC (pfile))
+	    cpp_error (pfile, CPP_DL_PEDWARN,
+		       "assertions are a GCC extension");
+	  else if (CPP_OPTION (pfile, warn_deprecated))
+	    cpp_error (pfile, CPP_DL_WARNING,
+		       "assertions are a deprecated extension");
+	}
       _cpp_test_assertion (pfile, &temp);
       result.high = 0;
       result.low = temp;
+      break;
+
+    default:
+      abort ();
     }
 
   result.unsignedp = !!unsignedp;

Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 120244)
+++ libcpp/directives.c	(working copy)
@@ -336,11 +337,18 @@
 static void
 directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented)
 {
-  /* Issue -pedantic warnings for extensions.  */
-  if (CPP_PEDANTIC (pfile)
-      && ! pfile->state.skipping
-      && dir->origin == EXTENSION)
-    cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name);
+  /* Issue -pedantic or deprecated warnings for extensions.  We let
+     -pedantic take precedence if both are applicable.  */
+  if (! pfile->state.skipping && dir->origin == EXTENSION)
+    {
+      if (CPP_PEDANTIC (pfile))
+	cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name);
+      else if (CPP_OPTION (pfile, warn_deprecated)
+	       && dir != &dtable[T_WARNING]
+	       && dir != &dtable[T_INCLUDE_NEXT])
+	cpp_error (pfile, CPP_DL_WARNING, "#%s is a deprecated GCC extension",
+		   dir->name);
+    }
 
   /* Traditionally, a directive is ignored unless its # is in
      column 1.  Therefore in code intended to work with K+R
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 120244)
+++ libcpp/init.c	(working copy)
@@ -156,7 +156,7 @@
   CPP_OPTION (pfile, operator_names) = 1;
   CPP_OPTION (pfile, warn_trigraphs) = 2;
   CPP_OPTION (pfile, warn_endif_labels) = 1;
-  CPP_OPTION (pfile, warn_deprecated) = 1;
+  CPP_OPTION (pfile, warn_deprecated) = 0;
   CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
   CPP_OPTION (pfile, dollars_in_ident) = 1;
   CPP_OPTION (pfile, warn_dollars) = 1;

Index: gcc/c.opt
===================================================================
--- gcc/c.opt	(revision 120096)
+++ gcc/c.opt	(working copy)
@@ -162,7 +162,7 @@
 Warn when a declaration is found after a statement
 
 Wdeprecated
-C++ ObjC++ Var(warn_deprecated) Init(1)
+C C++ ObjC++ Var(warn_deprecated) Init(1)
 Warn about deprecated compiler features
 
 Wdiv-by-zero

Index: gcc/testsuite/gcc.dg/cpp/pr22168-2.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr22168-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr22168-2.c	(revision 0)
@@ -0,0 +1,12 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.  */
+/* PR preprocessor/22168 */
+
+/* { dg-do preprocess }
+   { dg-options -Wdeprecated } */
+#if #foo(bar)    /* { dg-warning "deprecated" } */
+int x;
+#else
+int y;
+#endif
+#assert zzz(a)   /* { dg-warning "deprecated" } */
+#unassert yyy    /* { dg-warning "deprecated" } */
Index: gcc/testsuite/gcc.dg/cpp/pr22168.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr22168.c	(revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr22168.c	(revision 0)
@@ -0,0 +1,12 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.  */
+/* PR preprocessor/22168 */
+
+/* { dg-do preprocess }
+   { dg-options -pedantic } */
+#if #foo(bar)    /* { dg-warning "GCC extension" } */
+int x;
+#else
+int y;
+#endif
+#assert zzz(a)   /* { dg-warning "GCC extension" } */
+#unassert yyy    /* { dg-warning "GCC extension" } */
Index: gcc/testsuite/gcc.dg/cpp/assert4.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/assert4.c	(revision 120096)
+++ gcc/testsuite/gcc.dg/cpp/assert4.c	(working copy)
@@ -1,8 +1,9 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2006 Free Software Foundation, Inc.
    Test builtin preprocessor assertions.
    By Kaveh Ghazi <ghazi@caip.rutgers.edu>.  */
 
 /* { dg-do preprocess } */
+/* { dg-options -ansi } */
 
 /* Check for #system assertions.  */
 


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