OSDN Git Service

* cpplib.h (cpp_reader): Add new flag, no_directives.
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Feb 2000 21:41:35 +0000 (21:41 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Feb 2000 21:41:35 +0000 (21:41 +0000)
* cpphash.c (macarg): Set it.
* cpplib.c (handle_directive): If no_directives is on and we
find a directive, issue an error and discard the line.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@31763 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cpphash.c
gcc/cpplib.c
gcc/cpplib.h
gcc/testsuite/gcc.dg/undef.c [new file with mode: 0644]

index 9e38249..d3e73b9 100644 (file)
@@ -1,3 +1,10 @@
+2000-02-02  Zack Weinberg  <zack@wolery.cumb.org>
+
+       * cpplib.h (cpp_reader): Add new flag, no_directives.
+       * cpphash.c (macarg): Set it.
+       * cpplib.c (handle_directive): If no_directives is on and we
+       find a directive, issue an error and discard the line.
+
 Wed Feb  2 13:07:10 2000  Jim Wilson  <wilson@cygnus.com>
 
        * config/sparc/sparc.h (PREFERRED_RELOAD_CLASS): Delete 'E' check for
index 8a0c887..a7f19f1 100644 (file)
@@ -783,6 +783,7 @@ macarg (pfile, rest_args)
   /* Try to parse as much of the argument as exists at this
      input stack level.  */
   pfile->no_macro_expand++;
+  pfile->no_directives++;
   CPP_OPTIONS (pfile)->no_line_commands++;
   for (;;)
     {
@@ -823,6 +824,7 @@ done:
   CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
   CPP_OPTIONS (pfile)->no_line_commands--;
   pfile->no_macro_expand--;
+  pfile->no_directives--;
 
   return token;
 }
index cdfdaa3..5375d2b 100644 (file)
@@ -568,7 +568,15 @@ handle_directive (pfile)
     }
 
   CPP_SET_WRITTEN (pfile, old_written);
-  (*kt->func) (pfile, kt);
+
+  if (pfile->no_directives)
+    {
+      cpp_error (pfile, "`#%s' may not be used inside a macro argument",
+                kt->name);
+      skip_rest_of_line (pfile);
+    }
+  else
+    (*kt->func) (pfile, kt);
 
   return 1;
 }
index 882f462..c225916 100644 (file)
@@ -212,6 +212,11 @@ struct cpp_reader
   /* If non-zero, macros are not expanded. */
   char no_macro_expand;
 
+  /* If non-zero, directives cause a hard error.  Used when parsing
+     macro arguments.  */
+
+  char no_directives;
+
   /* Print column number in error messages. */
   char show_column;
 
diff --git a/gcc/testsuite/gcc.dg/undef.c b/gcc/testsuite/gcc.dg/undef.c
new file mode 100644 (file)
index 0000000..024efce
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do preprocess } */
+
+/* 6.9.3.11: ...If there  are sequences of preprocessing tokens within
+   the list of arguments  that  would  otherwise  act  as  preprocessing
+   directives, the behavior is undefined.
+
+   I choose to make this a hard error.  It definitely should not cause
+   a core dump.  */
+
+#define foo(bar) bar
+
+foo( blah
+#undef foo     /* { dg-error "may not be used inside" "foo(#undef foo)" } */
+     blah )