Commit 5237f531 by Zack Weinberg Committed by Zack Weinberg

cpplib.h (cpp_reader): Add new flag, no_directives.

	* 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.

From-SVN: r31763
parent 3e7cd49f
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> Wed Feb 2 13:07:10 2000 Jim Wilson <wilson@cygnus.com>
* config/sparc/sparc.h (PREFERRED_RELOAD_CLASS): Delete 'E' check for * config/sparc/sparc.h (PREFERRED_RELOAD_CLASS): Delete 'E' check for
......
...@@ -783,6 +783,7 @@ macarg (pfile, rest_args) ...@@ -783,6 +783,7 @@ macarg (pfile, rest_args)
/* Try to parse as much of the argument as exists at this /* Try to parse as much of the argument as exists at this
input stack level. */ input stack level. */
pfile->no_macro_expand++; pfile->no_macro_expand++;
pfile->no_directives++;
CPP_OPTIONS (pfile)->no_line_commands++; CPP_OPTIONS (pfile)->no_line_commands++;
for (;;) for (;;)
{ {
...@@ -823,6 +824,7 @@ done: ...@@ -823,6 +824,7 @@ done:
CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments; CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
CPP_OPTIONS (pfile)->no_line_commands--; CPP_OPTIONS (pfile)->no_line_commands--;
pfile->no_macro_expand--; pfile->no_macro_expand--;
pfile->no_directives--;
return token; return token;
} }
......
...@@ -568,7 +568,15 @@ handle_directive (pfile) ...@@ -568,7 +568,15 @@ handle_directive (pfile)
} }
CPP_SET_WRITTEN (pfile, old_written); 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; return 1;
} }
......
...@@ -212,6 +212,11 @@ struct cpp_reader ...@@ -212,6 +212,11 @@ struct cpp_reader
/* If non-zero, macros are not expanded. */ /* If non-zero, macros are not expanded. */
char no_macro_expand; 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. */ /* Print column number in error messages. */
char show_column; char show_column;
......
/* { 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 )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment