summaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-11-22 19:27:17 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-11-22 19:27:17 +0000
commita954677191450e00b53f8be75ab891052caea7ad (patch)
tree8a24c8b57eff44c8c440e11069452273d4a7c009 /gcc/c-family
parent56dce2cefd90467bfe57c5e4b9340553478e78be (diff)
downloadgcc-a954677191450e00b53f8be75ab891052caea7ad.tar.gz
In gcc/c-family/: 2010-11-22 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/c-family/: 2010-11-22 Nicola Pero <nicola.pero@meta-innovation.com> PR objc/34033 * c-lex.c (lex_string): Check that each string in an Objective-C string concat sequence starts with either one or zero '@', and that there are no spurious '@' signs at the end. In gcc/testsuite/: 2010-11-22 Nicola Pero <nicola.pero@meta-innovation.com> PR objc/34033 * objc.dg/strings-1.m: New. * objc.dg/strings-2.m: New. * obj-c++.dg/strings-1.mm: New. * obj-c++.dg/strings-2.mm: New. From-SVN: r167048
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog7
-rw-r--r--gcc/c-family/c-lex.c29
2 files changed, 30 insertions, 6 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 86e75ce84c9..fe6fe7ab732 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,10 @@
+2010-11-22 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ PR objc/34033
+ * c-lex.c (lex_string): Check that each string in an Objective-C
+ string concat sequence starts with either one or zero '@', and
+ that there are no spurious '@' signs at the end.
+
2010-11-20 Joseph Myers <joseph@codesourcery.com>
* c-pragma.c: Remove conditionals on HANDLE_PRAGMA_PACK,
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index 68a0fe04a5c..e372954f9ff 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -889,10 +889,12 @@ interpret_fixed (const cpp_token *token, unsigned int flags)
/* Convert a series of STRING, WSTRING, STRING16, STRING32 and/or
UTF8STRING tokens into a tree, performing string constant
- concatenation. TOK is the first of these. VALP is the location
- to write the string into. OBJC_STRING indicates whether an '@' token
- preceded the incoming token.
- Returns the CPP token type of the result (CPP_STRING, CPP_WSTRING,
+ concatenation. TOK is the first of these. VALP is the location to
+ write the string into. OBJC_STRING indicates whether an '@' token
+ preceded the incoming token (in that case, the strings can either
+ be ObjC strings, preceded by a single '@', or normal strings, not
+ preceded by '@'. The result will be a CPP_OBJC_STRING). Returns
+ the CPP token type of the result (CPP_STRING, CPP_WSTRING,
CPP_STRING32, CPP_STRING16, CPP_UTF8STRING, or CPP_OBJC_STRING).
This is unfortunately more work than it should be. If any of the
@@ -918,6 +920,12 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
cpp_string str = tok->val.str;
cpp_string *strs = &str;
+ /* objc_at_sign_was_seen is only used when doing Objective-C string
+ concatenation. It is 'true' if we have seen an '@' before the
+ current string, and 'false' if not. We must see exactly one or
+ zero '@' before each string. */
+ bool objc_at_sign_was_seen = false;
+
retry:
tok = cpp_get_token (parse_in);
switch (tok->type)
@@ -925,9 +933,12 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
case CPP_PADDING:
goto retry;
case CPP_ATSIGN:
- if (c_dialect_objc ())
+ if (objc_string)
{
- objc_string = true;
+ if (objc_at_sign_was_seen)
+ error ("repeated %<@%> before Objective-C string");
+
+ objc_at_sign_was_seen = true;
goto retry;
}
/* FALLTHROUGH */
@@ -956,9 +967,15 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
concats++;
obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
+ if (objc_string)
+ objc_at_sign_was_seen = false;
goto retry;
}
+ /* It is an error if we saw a '@' with no following string. */
+ if (objc_at_sign_was_seen)
+ error ("stray %<@%> in program");
+
/* We have read one more token than we want. */
_cpp_backup_tokens (parse_in, 1);
if (concats)