mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-19 03:50:26 +08:00
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
This commit is contained in:
parent
176a0aad11
commit
766beb4020
@ -1,3 +1,13 @@
|
||||
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
|
||||
|
12
gcc/c-decl.c
12
gcc/c-decl.c
@ -2312,26 +2312,26 @@ implicitly_declare (tree functionid)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -4803,10 +4803,11 @@ c_parser_postfix_expression (c_parser *parser)
|
||||
}
|
||||
{
|
||||
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;
|
||||
|
@ -379,7 +379,7 @@ extern void check_for_loop_decls (void);
|
||||
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);
|
||||
@ -463,7 +463,7 @@ extern tree composite_type (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 *);
|
||||
|
@ -1787,9 +1787,10 @@ build_array_ref (tree array, tree index)
|
||||
}
|
||||
|
||||
/* 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);
|
||||
@ -1809,7 +1810,7 @@ build_external_ref (tree id, int fun)
|
||||
return error_mark_node;
|
||||
else
|
||||
{
|
||||
undeclared_variable (id);
|
||||
undeclared_variable (id, loc);
|
||||
return error_mark_node;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
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
|
||||
|
13
gcc/testsuite/gcc.dg/pr8927-1.c
Normal file
13
gcc/testsuite/gcc.dg/pr8927-1.c
Normal file
@ -0,0 +1,13 @@
|
||||
/* 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" } */
|
||||
|
||||
|
||||
;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user