PR preprocessor/12935 preprocessor/12952 preprocessor/13046
authorNeil Booth <neil@daikokuya.co.uk>
Fri, 12 Dec 2003 07:00:29 +0000 (07:00 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Fri, 12 Dec 2003 07:00:29 +0000 (07:00 +0000)
PR preprocessor/12935 preprocessor/12952 preprocessor/13046
* cpplib.c (prepare_directive_trad): Clear skipping only in
#if and #elif directives.
(do_undef): Call the handler even if the identifier is not a macro.
* cpptrad.c (scan_parameters): Emit an error message.
(_cpp_create_trad_definition): Remember the params list even on
failure.
* testsuite/gcc.dg/cpp/trad/macro.c: New tests.

From-SVN: r74562

gcc/ChangeLog
gcc/cpplib.c
gcc/cpptrad.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/trad/macro.c [new file with mode: 0644]

index 08e75f5c90a3c228ae4fe483dd604b988655c258..ad91bf6c5f49c783c0fc82d07993b5d9da308700 100644 (file)
@@ -1,3 +1,13 @@
+2003-12-12  Neil Booth  <neil@daikokuya.co.uk>
+
+       PR preprocessor/12935 preprocessor/12952 preprocessor/13046
+       * cpplib.c (prepare_directive_trad): Clear skipping only in
+       #if and #elif directives.
+       (do_undef): Call the handler even if the identifier is not a macro.
+       * cpptrad.c (scan_parameters): Emit an error message.
+       (_cpp_create_trad_definition): Remember the params list even on
+       failure.
+
 2003-12-11  Zack Weinberg  <zack@codesourcery.com>
 
        * arm.c (ARM_ADDRESS_COST, THUMB_ADDRESS_COST): Convert macros
index 69995d49363b9201189f8c5ca6a4ba219170288a..2b213cb461a80bcd2a6fd9ac61c361a6c261f15e 100644 (file)
@@ -272,14 +272,17 @@ prepare_directive_trad (cpp_reader *pfile)
                        && ! (pfile->directive->flags & EXPAND));
       bool was_skipping = pfile->state.skipping;
 
-      pfile->state.skipping = false;
       pfile->state.in_expression = (pfile->directive == &dtable[T_IF]
                                    || pfile->directive == &dtable[T_ELIF]);
+      if (pfile->state.in_expression)
+       pfile->state.skipping = false;
+
       if (no_expand)
        pfile->state.prevent_expansion++;
       _cpp_scan_out_logical_line (pfile, NULL);
       if (no_expand)
        pfile->state.prevent_expansion--;
+
       pfile->state.skipping = was_skipping;
       _cpp_overlay_buffer (pfile, pfile->out.base,
                           pfile->out.cur - pfile->out.base);
@@ -520,22 +523,26 @@ do_undef (cpp_reader *pfile)
 {
   cpp_hashnode *node = lex_macro_node (pfile);
 
-  /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier
-     is not currently defined as a macro name.  */
-  if (node && node->type == NT_MACRO)
+  if (node)
     {
       if (pfile->cb.undef)
        pfile->cb.undef (pfile, pfile->directive_line, node);
 
-      if (node->flags & NODE_WARN)
-       cpp_error (pfile, CPP_DL_WARNING,
-                  "undefining \"%s\"", NODE_NAME (node));
+      /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified
+        identifier is not currently defined as a macro name.  */
+      if (node->type == NT_MACRO)
+       {
+         if (node->flags & NODE_WARN)
+           cpp_error (pfile, CPP_DL_WARNING,
+                      "undefining \"%s\"", NODE_NAME (node));
 
-      if (CPP_OPTION (pfile, warn_unused_macros))
-       _cpp_warn_if_unused_macro (pfile, node, NULL);
+         if (CPP_OPTION (pfile, warn_unused_macros))
+           _cpp_warn_if_unused_macro (pfile, node, NULL);
 
-      _cpp_free_definition (node);
+         _cpp_free_definition (node);
+       }
     }
+
   check_eol (pfile);
 }
 
index 6da19cc41ec980e4ac9c61188b2e8374ed09c6ba..08636edb7a591fac53eba7b0c415c6f3aafc777a 100644 (file)
@@ -907,6 +907,9 @@ scan_parameters (cpp_reader *pfile, cpp_macro *macro)
       break;
     }
 
+  if (!ok)
+    cpp_error (pfile, CPP_DL_ERROR, "syntax error in macro parameter list");
+
   CUR (pfile->context) = cur + (*cur == ')');
 
   return ok;
@@ -982,14 +985,17 @@ _cpp_create_trad_definition (cpp_reader *pfile, cpp_macro *macro)
   /* Is this a function-like macro?  */
   if (* CUR (context) == '(')
     {
+      bool ok = scan_parameters (pfile, macro);
+
+      /* Remember the params so we can clear NODE_MACRO_ARG flags.  */
+      macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
+
       /* Setting macro to NULL indicates an error occurred, and
         prevents unnecessary work in _cpp_scan_out_logical_line.  */
-      if (!scan_parameters (pfile, macro))
+      if (!ok)
        macro = NULL;
       else
        {
-         /* Success.  Commit the parameter array.  */
-         macro->params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
          BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
          macro->fun_like = 1;
        }
index 2dfae582a403ace84c802a677524bad0b5abc46c..358b09377dedaba832be65fa1e790bc2133309fb 100644 (file)
@@ -1,3 +1,7 @@
+2003-12-12  Neil Booth  <neil@daikokuya.co.uk>
+
+       * testsuite/gcc.dg/cpp/trad/macro.c: New tests.
+
 2003-12-11  Zack Weinberg  <zack@codesourcery.com>
 
        * gcc.c-torture/execute/wchar_t-1.x: Delete.
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/macro.c b/gcc/testsuite/gcc.dg/cpp/trad/macro.c
new file mode 100644 (file)
index 0000000..164b4ec
--- /dev/null
@@ -0,0 +1,11 @@
+/* Test that varargs are rejected, and that we don't complain about
+   macro args in skipped blocks.  */
+
+/* { dg-do preprocess } */
+
+#define f(x) 
+#define g(x, y...)             /* { dg-error "macro parameter list" } */
+
+#if 0
+#define f(a,b)                 /* { dg-bogus "passed 2 arguments" } */
+#endif