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]

cpplib: -Wtraditional and #elif


This updates -Wtraditional to suggest not using #elif - the
preprocessor that Michael uses does not accept it.

Requested by Kaveh.  Enhanced -Wtraditional documentation coming soon.

Neil.

	* cpplib.c (T_ELIF): Move to STDC89, not that it matters.
	(_cpp_handle_directive): Suggest not using #elif with -Wtraditional.

	* gcc.dg/cpp/tr-warn1.c: Add tests.

Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.238
diff -u -p -r1.238 cpplib.c
--- cpplib.c	2001/01/29 19:20:12	1.238
+++ cpplib.c	2001/01/31 07:50:41
@@ -128,7 +128,7 @@ D(else,		T_ELSE,		KANDR,     COND)	   /*
 D(ifndef,	T_IFNDEF,	KANDR,     COND | IF_COND) /*   9675 */ \
 D(undef,	T_UNDEF,	KANDR,     IN_I)	   /*   4837 */ \
 D(line,		T_LINE,		KANDR,     IN_I)	   /*   2465 */ \
-D(elif,		T_ELIF,		KANDR,     COND)	   /*    610 */ \
+D(elif,		T_ELIF,		STDC89,    COND)	   /*    610 */ \
 D(error,	T_ERROR,	STDC89,    0)		   /*    475 */ \
 D(pragma,	T_PRAGMA,	STDC89,    IN_I)	   /*    195 */ \
 D(warning,	T_WARNING,	EXTENSION, 0)		   /*     22 */ \
@@ -321,7 +321,10 @@ _cpp_handle_directive (pfile, indented)
 	     conditional blocks.  */
 	  if (CPP_WTRADITIONAL (pfile))
 	    {
-	      if (indented && dir->origin == KANDR)
+	      if (dir == &dtable[T_ELIF])
+		cpp_warning (pfile,
+			     "suggest not using #elif in traditional C");
+	      else if (indented && dir->origin == KANDR)
 		cpp_warning (pfile,
 			     "traditional C ignores #%s with the # indented",
 			     dir->name);
Index: testsuite/gcc.dg/cpp/tr-warn1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/cpp/tr-warn1.c,v
retrieving revision 1.2
diff -u -p -r1.2 tr-warn1.c
--- tr-warn1.c	2000/10/28 18:01:40	1.2
+++ tr-warn1.c	2001/01/31 07:50:41
@@ -24,6 +24,15 @@
  #assert baz(quux)	/* { dg-bogus "indented" "^ #ext"     } */
  # assert quux(weeble)	/* { dg-bogus "indented" "^ # ext"    } */
 
+/* We warn of #elif regardless of whether we're skipping or not, and
+   do not warn about indentaion.  */
+#if 0
+#if 1
+#elif 1			/* { dg-warning "#elif" "#elif skipping" }  */
+#endif
+#elif 0			/* { dg-warning "#elif" "#elif not skipping" }  */
+#endif
+
 /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 22 } */
 /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 23 } */
 /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 24 } */

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