mirror of git://gcc.gnu.org/git/gcc.git
re PR preprocessor/36320 (Required diagnosis of syntax error missed)
gcc/testsuite PR preprocessor/36320: * gcc.dg/cpp/pr36320.c: New file. libcpp PR preprocessor/36320: * internal.h (_cpp_parse_expr): Update. * expr.c (_cpp_parse_expr): Add 'is_if' argument. Update error messages. * directives.c (do_if): Update. (do_elif): Require expression if processing group. From-SVN: r136209
This commit is contained in:
parent
bfab40f8e5
commit
d750887f5f
|
|
@ -1,3 +1,8 @@
|
||||||
|
2008-05-30 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
PR preprocessor/36320:
|
||||||
|
* gcc.dg/cpp/pr36320.c: New file.
|
||||||
|
|
||||||
2008-05-29 Paolo Carlini <paolo.carlini@oracle.com>
|
2008-05-29 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
PR c++/35243
|
PR c++/35243
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
/* PR 36320 - #elif still requires valid expression. */
|
||||||
|
|
||||||
|
/* { dg-do preprocess } */
|
||||||
|
|
||||||
|
int z;
|
||||||
|
#if 1
|
||||||
|
#elif /* { dg-error "with no expression" } */
|
||||||
|
#endif
|
||||||
|
|
@ -1,3 +1,12 @@
|
||||||
|
2008-05-30 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
PR preprocessor/36320:
|
||||||
|
* internal.h (_cpp_parse_expr): Update.
|
||||||
|
* expr.c (_cpp_parse_expr): Add 'is_if' argument. Update error
|
||||||
|
messages.
|
||||||
|
* directives.c (do_if): Update.
|
||||||
|
(do_elif): Require expression if processing group.
|
||||||
|
|
||||||
2008-05-30 Danny Smith <dannysmith@users.sourceforge.net>
|
2008-05-30 Danny Smith <dannysmith@users.sourceforge.net>
|
||||||
|
|
||||||
* include/cpplib.h (struct cpp_dir): Add new field, canonical_name.
|
* include/cpplib.h (struct cpp_dir): Add new field, canonical_name.
|
||||||
|
|
|
||||||
|
|
@ -1737,7 +1737,7 @@ do_if (cpp_reader *pfile)
|
||||||
int skip = 1;
|
int skip = 1;
|
||||||
|
|
||||||
if (! pfile->state.skipping)
|
if (! pfile->state.skipping)
|
||||||
skip = _cpp_parse_expr (pfile) == false;
|
skip = _cpp_parse_expr (pfile, true) == false;
|
||||||
|
|
||||||
push_conditional (pfile, skip, T_IF, pfile->mi_ind_cmacro);
|
push_conditional (pfile, skip, T_IF, pfile->mi_ind_cmacro);
|
||||||
}
|
}
|
||||||
|
|
@ -1796,15 +1796,23 @@ do_elif (cpp_reader *pfile)
|
||||||
}
|
}
|
||||||
ifs->type = T_ELIF;
|
ifs->type = T_ELIF;
|
||||||
|
|
||||||
/* Only evaluate this if we aren't skipping elses. During
|
if (! ifs->was_skipping)
|
||||||
evaluation, set skipping to false to get lexer warnings. */
|
|
||||||
if (ifs->skip_elses)
|
|
||||||
pfile->state.skipping = 1;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
bool value;
|
||||||
|
/* The standard mandates that the expression be parsed even
|
||||||
|
if we are skipping elses at this point -- the lexical
|
||||||
|
restrictions on #elif only apply to skipped groups, but
|
||||||
|
this group is not being skipped. Temporarily set
|
||||||
|
skipping to false to get lexer warnings. */
|
||||||
pfile->state.skipping = 0;
|
pfile->state.skipping = 0;
|
||||||
pfile->state.skipping = ! _cpp_parse_expr (pfile);
|
value = _cpp_parse_expr (pfile, false);
|
||||||
ifs->skip_elses = ! pfile->state.skipping;
|
if (ifs->skip_elses)
|
||||||
|
pfile->state.skipping = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pfile->state.skipping = ! value;
|
||||||
|
ifs->skip_elses = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invalidate any controlling macro. */
|
/* Invalidate any controlling macro. */
|
||||||
|
|
|
||||||
|
|
@ -852,7 +852,7 @@ static const struct cpp_operator
|
||||||
stored in the 'value' field of the stack element of the operator
|
stored in the 'value' field of the stack element of the operator
|
||||||
that precedes it. */
|
that precedes it. */
|
||||||
bool
|
bool
|
||||||
_cpp_parse_expr (cpp_reader *pfile)
|
_cpp_parse_expr (cpp_reader *pfile, bool is_if)
|
||||||
{
|
{
|
||||||
struct op *top = pfile->op_stack;
|
struct op *top = pfile->op_stack;
|
||||||
unsigned int lex_count;
|
unsigned int lex_count;
|
||||||
|
|
@ -927,7 +927,7 @@ _cpp_parse_expr (cpp_reader *pfile)
|
||||||
SYNTAX_ERROR ("missing expression between '(' and ')'");
|
SYNTAX_ERROR ("missing expression between '(' and ')'");
|
||||||
|
|
||||||
if (op.op == CPP_EOF && top->op == CPP_EOF)
|
if (op.op == CPP_EOF && top->op == CPP_EOF)
|
||||||
SYNTAX_ERROR ("#if with no expression");
|
SYNTAX_ERROR2 ("%s with no expression", is_if ? "#if" : "#elif");
|
||||||
|
|
||||||
if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
|
if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
|
||||||
SYNTAX_ERROR2 ("operator '%s' has no right operand",
|
SYNTAX_ERROR2 ("operator '%s' has no right operand",
|
||||||
|
|
@ -988,7 +988,8 @@ _cpp_parse_expr (cpp_reader *pfile)
|
||||||
|
|
||||||
if (top != pfile->op_stack)
|
if (top != pfile->op_stack)
|
||||||
{
|
{
|
||||||
cpp_error (pfile, CPP_DL_ICE, "unbalanced stack in #if");
|
cpp_error (pfile, CPP_DL_ICE, "unbalanced stack in %s",
|
||||||
|
is_if ? "#if" : "#elif");
|
||||||
syntax_error:
|
syntax_error:
|
||||||
return false; /* Return false on syntax error. */
|
return false; /* Return false on syntax error. */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -557,7 +557,7 @@ extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
|
||||||
extern struct stat *_cpp_get_file_stat (_cpp_file *);
|
extern struct stat *_cpp_get_file_stat (_cpp_file *);
|
||||||
|
|
||||||
/* In expr.c */
|
/* In expr.c */
|
||||||
extern bool _cpp_parse_expr (cpp_reader *);
|
extern bool _cpp_parse_expr (cpp_reader *, bool);
|
||||||
extern struct op *_cpp_expand_op_stack (cpp_reader *);
|
extern struct op *_cpp_expand_op_stack (cpp_reader *);
|
||||||
|
|
||||||
/* In lex.c */
|
/* In lex.c */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue