Commit 766beb40 by Joseph Myers Committed by Joseph Myers

re PR c/8927 (Gcc give error for wrong line of C code.)

	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.

testsuite:
	* gcc.dg/pr8927-1.c: New test.

From-SVN: r95773
parent 176a0aad
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> 2005-03-01 David Edelsohn <edelsohn@gnu.org>
* config/rs6000/rs6000.md (cceq splitter): Use operand mode, not * config/rs6000/rs6000.md (cceq splitter): Use operand mode, not
......
...@@ -2312,26 +2312,26 @@ implicitly_declare (tree functionid) ...@@ -2312,26 +2312,26 @@ implicitly_declare (tree functionid)
ID, including a reference to a builtin outside of function-call ID, including a reference to a builtin outside of function-call
context. Establish a binding of the identifier to error_mark_node context. Establish a binding of the identifier to error_mark_node
in an appropriate scope, which will suppress further errors for the in an appropriate scope, which will suppress further errors for the
same identifier. */ same identifier. The error message should be given location LOC. */
void void
undeclared_variable (tree id) undeclared_variable (tree id, location_t loc)
{ {
static bool already = false; static bool already = false;
struct c_scope *scope; struct c_scope *scope;
if (current_function_decl == 0) 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; scope = current_scope;
} }
else else
{ {
error ("%qE undeclared (first use in this function)", id); error ("%H%qE undeclared (first use in this function)", &loc, id);
if (!already) if (!already)
{ {
error ("(Each undeclared identifier is reported only once"); error ("%H(Each undeclared identifier is reported only once", &loc);
error ("for each function it appears in.)"); error ("%Hfor each function it appears in.)", &loc);
already = true; already = true;
} }
......
...@@ -4803,10 +4803,11 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -4803,10 +4803,11 @@ c_parser_postfix_expression (c_parser *parser)
} }
{ {
tree id = c_parser_peek_token (parser)->value; tree id = c_parser_peek_token (parser)->value;
location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser); c_parser_consume_token (parser);
expr.value = build_external_ref (id, expr.value = build_external_ref (id,
(c_parser_peek_token (parser)->type (c_parser_peek_token (parser)->type
== CPP_OPEN_PAREN)); == CPP_OPEN_PAREN), loc);
expr.original_code = ERROR_MARK; expr.original_code = ERROR_MARK;
} }
break; break;
......
...@@ -379,7 +379,7 @@ extern void check_for_loop_decls (void); ...@@ -379,7 +379,7 @@ extern void check_for_loop_decls (void);
extern void mark_forward_parm_decls (void); extern void mark_forward_parm_decls (void);
extern int complete_array_type (tree, tree, int); extern int complete_array_type (tree, tree, int);
extern void declare_parm_level (void); 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 declare_label (tree);
extern tree define_label (location_t, tree); extern tree define_label (location_t, tree);
extern void finish_decl (tree, tree, tree); extern void finish_decl (tree, tree, tree);
...@@ -463,7 +463,7 @@ extern tree composite_type (tree, tree); ...@@ -463,7 +463,7 @@ extern tree composite_type (tree, tree);
extern tree build_component_ref (tree, tree); extern tree build_component_ref (tree, tree);
extern tree build_indirect_ref (tree, const char *); extern tree build_indirect_ref (tree, const char *);
extern tree build_array_ref (tree, tree); 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 void pop_maybe_used (bool);
extern struct c_expr c_expr_sizeof_expr (struct c_expr); extern struct c_expr c_expr_sizeof_expr (struct c_expr);
extern struct c_expr c_expr_sizeof_type (struct c_type_name *); extern struct c_expr c_expr_sizeof_type (struct c_type_name *);
......
...@@ -1787,9 +1787,10 @@ build_array_ref (tree array, tree index) ...@@ -1787,9 +1787,10 @@ build_array_ref (tree array, tree index)
} }
/* Build an external reference to identifier ID. FUN indicates /* 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 tree
build_external_ref (tree id, int fun) build_external_ref (tree id, int fun, location_t loc)
{ {
tree ref; tree ref;
tree decl = lookup_name (id); tree decl = lookup_name (id);
...@@ -1809,7 +1810,7 @@ build_external_ref (tree id, int fun) ...@@ -1809,7 +1810,7 @@ build_external_ref (tree id, int fun)
return error_mark_node; return error_mark_node;
else else
{ {
undeclared_variable (id); undeclared_variable (id, loc);
return error_mark_node; 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> 2005-03-01 Nathan Sidwell <nathan@codesourcery.com>
PR c++/20232 PR c++/20232
......
/* 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" } */
;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment