+2005-03-02 Joseph S. Myers <joseph@codesourcery.com>
+
+ PR c/8927
+ * c-tree.h (undeclared_variable, build_external_ref): Add extra
+ argument.
+ * c-decl.c (undeclared_variable): Take location as argument.
+ * c-typeck.c (build_external_ref): Likewise.
+ * c-parser.c (c_parser_postfix_expression): Pass location of
+ identifier to build_external_ref.
+
2005-03-01 David Edelsohn <edelsohn@gnu.org>
* config/rs6000/rs6000.md (cceq splitter): Use operand mode, not
ID, including a reference to a builtin outside of function-call
context. Establish a binding of the identifier to error_mark_node
in an appropriate scope, which will suppress further errors for the
- same identifier. */
+ same identifier. The error message should be given location LOC. */
void
-undeclared_variable (tree id)
+undeclared_variable (tree id, location_t loc)
{
static bool already = false;
struct c_scope *scope;
if (current_function_decl == 0)
{
- error ("%qE undeclared here (not in a function)", id);
+ error ("%H%qE undeclared here (not in a function)", &loc, id);
scope = current_scope;
}
else
{
- error ("%qE undeclared (first use in this function)", id);
+ error ("%H%qE undeclared (first use in this function)", &loc, id);
if (!already)
{
- error ("(Each undeclared identifier is reported only once");
- error ("for each function it appears in.)");
+ error ("%H(Each undeclared identifier is reported only once", &loc);
+ error ("%Hfor each function it appears in.)", &loc);
already = true;
}
}
{
tree id = c_parser_peek_token (parser)->value;
+ location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
expr.value = build_external_ref (id,
(c_parser_peek_token (parser)->type
- == CPP_OPEN_PAREN));
+ == CPP_OPEN_PAREN), loc);
expr.original_code = ERROR_MARK;
}
break;
extern void mark_forward_parm_decls (void);
extern int complete_array_type (tree, tree, int);
extern void declare_parm_level (void);
-extern void undeclared_variable (tree);
+extern void undeclared_variable (tree, location_t);
extern tree declare_label (tree);
extern tree define_label (location_t, tree);
extern void finish_decl (tree, tree, tree);
extern tree build_component_ref (tree, tree);
extern tree build_indirect_ref (tree, const char *);
extern tree build_array_ref (tree, tree);
-extern tree build_external_ref (tree, int);
+extern tree build_external_ref (tree, int, location_t);
extern void pop_maybe_used (bool);
extern struct c_expr c_expr_sizeof_expr (struct c_expr);
extern struct c_expr c_expr_sizeof_type (struct c_type_name *);
}
\f
/* Build an external reference to identifier ID. FUN indicates
- whether this will be used for a function call. */
+ whether this will be used for a function call. LOC is the source
+ location of the identifier. */
tree
-build_external_ref (tree id, int fun)
+build_external_ref (tree id, int fun, location_t loc)
{
tree ref;
tree decl = lookup_name (id);
return error_mark_node;
else
{
- undeclared_variable (id);
+ undeclared_variable (id, loc);
return error_mark_node;
}
+2005-03-02 Joseph S. Myers <joseph@codesourcery.com>
+
+ PR c/8927
+ * gcc.dg/pr8927-1.c: New test.
+
2005-03-01 Nathan Sidwell <nathan@codesourcery.com>
PR c++/20232
--- /dev/null
+/* Bug 8927: undeclared identifiers should give an error on the line
+ of that identifier, not on the line of the next token. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo(void)
+{
+ bar /* { dg-error "undeclared|for each function" } */
+
+
+ ;
+}