diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-06-28 20:28:07 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-06-28 20:28:07 +0000 |
commit | 5fcb4428315efff7214234c07d4e5323b26454f2 (patch) | |
tree | 02bd01c5a5906c0b82dec447bea2de9e403804c7 | |
parent | 69716e795148ece3f2ee93e438fb88fe298cc16d (diff) | |
download | gcc-5fcb4428315efff7214234c07d4e5323b26454f2.tar.gz |
PR preprocessor/16192
PR preprocessor/15913
PR preprocessor/15572
* cppexp.c (_cpp_parse_expr): Handle remaining cases where an
expression is missing.
* cppinit.c (post_options): Traditional cpp doesn't do // comments.
* doc/cpp.texi: Don't document what we do for ill-formed expressions.
* doc/cppopts.texi: Clarify processing of command-line defines.
testsuite:
* gcc.dg/cpp/if-mop.c: Two new testcases.
* gcc.dg/cpp/trad/comment-3.c: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-3_4-branch@83813 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cppexp.c | 20 | ||||
-rw-r--r-- | gcc/cppinit.c | 2 | ||||
-rw-r--r-- | gcc/doc/cpp.texi | 3 | ||||
-rw-r--r-- | gcc/doc/cppopts.texi | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/if-mop.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/trad/comment-3.c | 6 |
6 files changed, 34 insertions, 15 deletions
diff --git a/gcc/cppexp.c b/gcc/cppexp.c index 5603f5bd58a..cb35b6c782f 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -745,18 +745,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) + /* 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); diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 0776476b0e9..ae30568699c 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -618,6 +618,8 @@ post_options (cpp_reader *pfile) if (CPP_OPTION (pfile, traditional)) { + CPP_OPTION (pfile, cplusplus_comments) = 0; + /* Traditional CPP does not accurately track column information. */ CPP_OPTION (pfile, show_column) = 0; CPP_OPTION (pfile, trigraphs) = 0; diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index 5d1cb9b3029..8080342b889 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -2960,9 +2960,6 @@ expression, and may give different results in some cases. If the value comes out to be nonzero, the @samp{#if} succeeds and the @var{controlled text} is included; otherwise it is skipped. -If @var{expression} is not correctly formed, GCC issues an error and -treats the conditional as having failed. - @node Defined @subsection Defined diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index fb8f5c72122..6e784de1f50 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -17,10 +17,14 @@ Predefine @var{name} as a macro, with definition @code{1}. @item -D @var{name}=@var{definition} Predefine @var{name} as a macro, with definition @var{definition}. -There are no restrictions on the contents of @var{definition}, but if -you are invoking the preprocessor from a shell or shell-like program you -may need to use the shell's quoting syntax to protect characters such as -spaces that have a meaning in the shell syntax. +The contents of @var{definition} are tokenized and processed as if +they appeared during translation phase three in a @samp{#define} +directive. In particular, the definition will be truncated by +embedded newline characters. + +If you are invoking the preprocessor from a shell or shell-like +program you may need to use the shell's quoting syntax to protect +characters such as spaces that have a meaning in the shell syntax. If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign diff --git a/gcc/testsuite/gcc.dg/cpp/if-mop.c b/gcc/testsuite/gcc.dg/cpp/if-mop.c index 9202740e6b1..119c7392e06 100644 --- a/gcc/testsuite/gcc.dg/cpp/if-mop.c +++ b/gcc/testsuite/gcc.dg/cpp/if-mop.c @@ -23,3 +23,9 @@ #if (2) 4 * 2 /* { dg-error "missing bin" "close paren then immediate" } */ #endif + +#if == 2 /* { dg-error "no left op" } */ +#endif + +#if (==2) /* { dg-error "no left op" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/cpp/trad/comment-3.c b/gcc/testsuite/gcc.dg/cpp/trad/comment-3.c new file mode 100644 index 00000000000..e2710ad5629 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/trad/comment-3.c @@ -0,0 +1,6 @@ +/* Test we don't accept C++ comments. */ + +/* { dg-do preprocess } */ + +#if 0 +#endif // /* { dg-warning "extra tokens" } */ |