PR c++/14875
* c-common.c (c_parse_error): Take a token_flags parameter.
Use token_type for the token type instead.
Pass token_flags to cpp_type2name.
* c-common.h (c_parse_error): Update declaration.
* c-parser.c (c_parser_error): Pass 0 as token flags.
libcpp/
* lex.c (cpp_type2name): Take a flags parameter. Call
cpp_named_operator2name for named operators and cpp_digraph2name
for digraphs.
(cpp_digraph2name): New.
(cpp_spell_token): Use it.
(cpp_output_token): Likewise.
* include/cpplib.h (cpp_type2name): Update declaration.
* init.c (cpp_named_operator2name): New.
* internal.h (cpp_named_operator2name): Declare.
cp/
* parser.c (cp_parser_error): Pass token->flags to c_parse_error.
testsuite/
* g++.dg/parse/parser-pr14875.C: New.
* g++.dg/parse/parser-pr14875-2.C: New.
* g++.dg/parse/error6.C: Update match string.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146589
138bc75d-0d04-0410-961f-
82ee72b054a4
+2009-04-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ PR c++/14875
+ * c-common.c (c_parse_error): Take a token_flags parameter.
+ Use token_type for the token type instead.
+ Pass token_flags to cpp_type2name.
+ * c-common.h (c_parse_error): Update declaration.
+ * c-parser.c (c_parser_error): Pass 0 as token flags.
+
2009-04-22 Andrey Belevantsev <abel@ispras.ru>
PR rtl-optimization/39580
TOKEN, which had the associated VALUE. */
void
-c_parse_error (const char *gmsgid, enum cpp_ttype token, tree value)
+c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
+ tree value, unsigned char token_flags)
{
#define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
char *message = NULL;
- if (token == CPP_EOF)
+ if (token_type == CPP_EOF)
message = catenate_messages (gmsgid, " at end of input");
- else if (token == CPP_CHAR || token == CPP_WCHAR || token == CPP_CHAR16
- || token == CPP_CHAR32)
+ else if (token_type == CPP_CHAR
+ || token_type == CPP_WCHAR
+ || token_type == CPP_CHAR16
+ || token_type == CPP_CHAR32)
{
unsigned int val = TREE_INT_CST_LOW (value);
const char *prefix;
- switch (token)
+ switch (token_type)
{
default:
prefix = "";
free (message);
message = NULL;
}
- else if (token == CPP_STRING || token == CPP_WSTRING || token == CPP_STRING16
- || token == CPP_STRING32)
+ else if (token_type == CPP_STRING
+ || token_type == CPP_WSTRING
+ || token_type == CPP_STRING16
+ || token_type == CPP_STRING32)
message = catenate_messages (gmsgid, " before string constant");
- else if (token == CPP_NUMBER)
+ else if (token_type == CPP_NUMBER)
message = catenate_messages (gmsgid, " before numeric constant");
- else if (token == CPP_NAME)
+ else if (token_type == CPP_NAME)
{
message = catenate_messages (gmsgid, " before %qE");
error (message, value);
free (message);
message = NULL;
}
- else if (token == CPP_PRAGMA)
+ else if (token_type == CPP_PRAGMA)
message = catenate_messages (gmsgid, " before %<#pragma%>");
- else if (token == CPP_PRAGMA_EOL)
+ else if (token_type == CPP_PRAGMA_EOL)
message = catenate_messages (gmsgid, " before end of line");
- else if (token < N_TTYPES)
+ else if (token_type < N_TTYPES)
{
message = catenate_messages (gmsgid, " before %qs token");
- error (message, cpp_type2name (token));
+ error (message, cpp_type2name (token_type, token_flags));
free (message);
message = NULL;
}
extern void builtin_define_with_value (const char *, const char *, int);
extern void c_stddef_cpp_builtins (void);
extern void fe_file_change (const struct line_map *);
-extern void c_parse_error (const char *, enum cpp_ttype, tree);
+extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char);
/* Objective-C / Objective-C++ entry points. */
CPP_KEYWORD, keywords are treated like
identifiers. */
(token->type == CPP_KEYWORD ? CPP_NAME : token->type),
- token->value);
+ /* ??? The C parser does not save the cpp flags of a
+ token, we need to pass 0 here and we will not get
+ the source spelling of some tokens but rather the
+ canonical spelling. */
+ token->value, /*flags=*/0);
}
/* If the next token is of the indicated TYPE, consume it. Otherwise,
+2009-04-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ PR c++/14875
+ * parser.c (cp_parser_error): Pass token->flags to c_parse_error.
+
2009-04-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/35711
CPP_KEYWORD, keywords are treated like
identifiers. */
(token->type == CPP_KEYWORD ? CPP_NAME : token->type),
- token->u.value);
+ token->u.value, token->flags);
}
}
+2009-04-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ PR c++/14875
+ * g++.dg/parse/parser-pr14875.C: New.
+ * g++.dg/parse/parser-pr14875-2.C: New.
+ * g++.dg/parse/error6.C: Update match string.
+
2009-04-22 Richard Guenther <rguenther@suse.de>
PR tree-optimization/39845
return 1-not;
}
-// { dg-error "11:expected ',' or '...' before '!' token" "" { target *-*-* } 4 }
+// { dg-error "11:expected ',' or '...' before 'not' token" "" { target *-*-* } 4 }
// { dg-error "15:expected primary\\-expression before ';' token" "" { target *-*-* } 5 }
--- /dev/null
+// PR 14875: When using 'or' keyword, the error message speaks of a '||' token
+// { dg-do compile }
+// { dg-options "" }
+#define CHECK(x) void ::x
+ CHECK (and); // { dg-error "before .and. token" }
+ CHECK (and_eq); // { dg-error "before .and_eq. token" }
+ CHECK (bitand); // { dg-error "before .bitand. token" }
+ CHECK (bitor); // { dg-error "before .bitor. token" }
+ CHECK (compl); // { dg-error "before .compl. token" }
+ CHECK (not); // { dg-error "before .not. token" }
+ CHECK (not_eq); // { dg-error "before .not_eq. token" }
+ CHECK (or); // { dg-error "before .or. token" }
+ CHECK (or_eq); // { dg-error "before .or_eq. token" }
+ CHECK (xor); // { dg-error "before .xor. token" }
+ CHECK (xor_eq); // { dg-error "before .xor_eq. token" }
+#undef CHECK
+#define CHECK(x) int x
+ CHECK (<:); // { dg-error "before .<:. token" }
+ CHECK (:>); // { dg-error "before .:>. token" }
+#undef CHECK
+#define CHECK(x) x
+ CHECK (<%); // { dg-error "before .<%. token" }
+#undef CHECK
+#define CHECK(x) x x
+ CHECK (%>); // { dg-error "before .%>. token" }
+#undef CHECK
+#define CHECK(x) x
+ CHECK (%:); // { dg-error "stray .%:. " }
+ CHECK (%:%:); // { dg-error "stray .%:%:. " }
+
+
--- /dev/null
+// PR 14875: When using 'or' keyword, the error message speaks of a '||' token
+// { dg-do compile }
+// { dg-options "" }
+using namespace std;
+
+class Sample
+{
+
+public:
+ Sample();
+ void or(long Digital); // { dg-error "before .or. token" }
+};
+
+Sample::Sample()
+{
+}
+
+void Sample::or(long Digital) // { dg-error "before .or. token" }
+{
+}
+2009-04-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ PR c++/14875
+ * lex.c (cpp_type2name): Take a flags parameter. Call
+ cpp_named_operator2name for named operators and cpp_digraph2name
+ for digraphs.
+ (cpp_digraph2name): New.
+ (cpp_spell_token): Use it.
+ (cpp_output_token): Likewise.
+ * include/cpplib.h (cpp_type2name): Update declaration.
+ * init.c (cpp_named_operator2name): New.
+ * internal.h (cpp_named_operator2name): Declare.
+
2009-04-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/13358
extern unsigned char *cpp_output_line_to_string (cpp_reader *,
const unsigned char *);
extern void cpp_output_token (const cpp_token *, FILE *);
-extern const char *cpp_type2name (enum cpp_ttype);
+extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags);
/* Returns the value of an escape sequence, truncated to the correct
target precision. PSTR points to the input pointer, which is just
after the backslash. LIMIT is how much text we have. WIDE is true
}
}
+/* Helper function of cpp_type2name. Return the string associated with
+ named operator TYPE. */
+const char *
+cpp_named_operator2name (enum cpp_ttype type)
+{
+ const struct builtin_operator *b;
+
+ for (b = operator_array;
+ b < (operator_array + ARRAY_SIZE (operator_array));
+ b++)
+ {
+ if (type == b->value)
+ return (const char *) b->name;
+ }
+
+ return NULL;
+}
+
void
cpp_init_special_builtins (cpp_reader *pfile)
{
/* In init.c. */
extern void _cpp_maybe_push_include_file (cpp_reader *);
+extern const char *cpp_named_operator2name (enum cpp_ttype type);
/* In directives.c */
extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
return ucn_len;
}
+/* Given a token TYPE corresponding to a digraph, return a pointer to
+ the spelling of the digraph. */
+static const unsigned char *
+cpp_digraph2name (enum cpp_ttype type)
+{
+ return digraph_spellings[(int) type - (int) CPP_FIRST_DIGRAPH];
+}
/* Write the spelling of a token TOKEN to BUFFER. The buffer must
already contain the enough space to hold the token's spelling.
unsigned char c;
if (token->flags & DIGRAPH)
- spelling
- = digraph_spellings[(int) token->type - (int) CPP_FIRST_DIGRAPH];
+ spelling = cpp_digraph2name (token->type);
else if (token->flags & NAMED_OP)
goto spell_ident;
else
return start;
}
-/* Used by C front ends, which really should move to using
- cpp_token_as_text. */
+/* Returns a pointer to a string which spells the token defined by
+ TYPE and FLAGS. Used by C front ends, which really should move to
+ using cpp_token_as_text. */
const char *
-cpp_type2name (enum cpp_ttype type)
+cpp_type2name (enum cpp_ttype type, unsigned char flags)
{
+ if (flags & DIGRAPH)
+ return (const char *) cpp_digraph2name (type);
+ else if (flags & NAMED_OP)
+ return cpp_named_operator2name (type);
+
return (const char *) token_spellings[type].name;
}
int c;
if (token->flags & DIGRAPH)
- spelling
- = digraph_spellings[(int) token->type - (int) CPP_FIRST_DIGRAPH];
+ spelling = cpp_digraph2name (token->type);
else if (token->flags & NAMED_OP)
goto spell_ident;
else