aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorsimartin <>2007-05-23 19:58:34 +0000
committersimartin <>2007-05-23 19:58:34 +0000
commit10679fced93d35c013b03eb167e0c8283c7a4cb8 (patch)
treea044b3337600d63cb8999a4a4f4063b685f09fa7 /libcpp
parent4effc004ff6452372523a874ffb9967b98734793 (diff)
2007-05-23 Simon Martin <simartin@users.sourceforge.net>
PR preprocessor/20077 * macro.c (create_iso_definition): Fixed the method to determine whether the token-pasting operator appears at the beginning or the end of a macro.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/macro.c27
2 files changed, 26 insertions, 8 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 44023594743..8f760cc1d95 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2007-05-23 Simon Martin <simartin@users.sourceforge.net>
+
+ PR preprocessor/20077
+ * macro.c (create_iso_definition): Fixed the method to determine
+ whether the token-pasting operator appears at the beginning or the end
+ of a macro.
+
2007-05-21 Ian Lance Taylor <iant@google.com>
* internal.h (struct cpp_reader): Add new fields:
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 748635f408e..12681c34338 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -1434,6 +1434,9 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
{
cpp_token *token;
const cpp_token *ctoken;
+ bool following_paste_op = false;
+ const char *paste_op_error_msg =
+ N_("'##' cannot appear at either end of a macro expansion");
/* Get the first token of the expansion (or the '(' of a
function-like macro). */
@@ -1527,26 +1530,34 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
}
if (token->type == CPP_EOF)
- break;
+ {
+ /* Paste operator constraint 6.10.3.3.1:
+ Token-paste ##, can appear in both object-like and
+ function-like macros, but not at the end. */
+ if (following_paste_op)
+ {
+ cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
+ return false;
+ }
+ break;
+ }
/* Paste operator constraint 6.10.3.3.1. */
if (token->type == CPP_PASTE)
{
/* Token-paste ##, can appear in both object-like and
- function-like macros, but not at the ends. */
- if (--macro->count > 0)
- token = lex_expansion_token (pfile, macro);
-
- if (macro->count == 0 || token->type == CPP_EOF)
+ function-like macros, but not at the beginning. */
+ if (macro->count == 1)
{
- cpp_error (pfile, CPP_DL_ERROR,
- "'##' cannot appear at either end of a macro expansion");
+ cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg);
return false;
}
+ --macro->count;
token[-1].flags |= PASTE_LEFT;
}
+ following_paste_op = (token->type == CPP_PASTE);
token = lex_expansion_token (pfile, macro);
}