aboutsummaryrefslogtreecommitdiff
path: root/libcpp/expr.c
diff options
context:
space:
mode:
authorNeil Booth <neil@duron.akihabara.co.uk>2004-07-04 12:57:50 +0000
committerNeil Booth <neil@gcc.gnu.org>2004-07-04 12:57:50 +0000
commita09d4744294e28a19e7f785e85a361d2cd34c25e (patch)
tree7aa5c20469e6c104827c6efe34863e1cdbc76042 /libcpp/expr.c
parentb25c17bcf0525adb212c2f08fa2607a0543630a8 (diff)
downloadgcc-a09d4744294e28a19e7f785e85a361d2cd34c25e.zip
gcc-a09d4744294e28a19e7f785e85a361d2cd34c25e.tar.gz
gcc-a09d4744294e28a19e7f785e85a361d2cd34c25e.tar.bz2
re PR preprocessor/16192 (Bug in expression evaluation when operand is missing)
* doc/cpp.texi: Don't document what we do for ill-formed expressions. * doc/cppopts.texi: Clarify processing of command-line defines. libcpp: PR preprocessor/16192 PR preprocessor/15913 PR preprocessor/15572 * expr.c (_cpp_parse_expr): Handle remaining cases where an expression is missing. * init.c (post_options): Traditional cpp doesn't do // comments. testsuite: * gcc.dg/cpp/if-mop.c: Two new testcases. * gcc.dg/cpp/trad/comment-3.c: New. From-SVN: r84080
Diffstat (limited to 'libcpp/expr.c')
-rw-r--r--libcpp/expr.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libcpp/expr.c b/libcpp/expr.c
index f49bd08..4768918 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -747,18 +747,22 @@ _cpp_parse_expr (cpp_reader *pfile)
}
else if (want_value)
{
- /* Ordering here is subtle and intended to favor the
- missing parenthesis diagnostics over alternatives. */
- if (op.op == CPP_CLOSE_PAREN)
- {
- if (top->op == CPP_OPEN_PAREN)
- SYNTAX_ERROR ("void expression between '(' and ')'");
- }
- else if (top->op == CPP_EOF)
- SYNTAX_ERROR ("#if with no expression");
- if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
- SYNTAX_ERROR2 ("operator '%s' has no right operand",
- cpp_token_as_text (pfile, top->token));
+ /* We want a number (or expression) and haven't got one.
+ Try to emit a specific diagnostic. */
+ if (op.op == CPP_CLOSE_PAREN && top->op == CPP_OPEN_PAREN)
+ SYNTAX_ERROR ("missing expression between '(' and ')'");
+
+ if (op.op == CPP_EOF && top->op == CPP_EOF)
+ SYNTAX_ERROR ("#if with no expression");
+
+ if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN)
+ SYNTAX_ERROR2 ("operator '%s' has no right operand",
+ cpp_token_as_text (pfile, top->token));
+ else if (op.op == CPP_CLOSE_PAREN || op.op == CPP_EOF)
+ /* Complain about missing paren during reduction. */;
+ else
+ SYNTAX_ERROR2 ("operator '%s' has no left operand",
+ cpp_token_as_text (pfile, op.token));
}
top = reduce (pfile, top, op.op);