From: jsm28 Date: Wed, 2 Mar 2005 02:50:25 +0000 (+0000) Subject: PR c/8927 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8dc938b96836b81a9641e3d0815aa1338a99b17c;p=thirdparty%2Fgcc.git 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95773 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d4309b595031..46f4c118758d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2005-03-02 Joseph S. Myers + + 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 * config/rs6000/rs6000.md (cceq splitter): Use operand mode, not diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 690d3b3bc801..5cad16ee69fe 100644 --- a/gcc/c-decl.c +++ b/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; } diff --git a/gcc/c-parser.c b/gcc/c-parser.c index de6999a0add4..e08f436b46e4 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -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; diff --git a/gcc/c-tree.h b/gcc/c-tree.h index d16d6a6892d4..18b2634c1b74 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -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 *); diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 3a38d22923b5..ea1c81c7435a 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5e3ceaa2078c..d72534301c68 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-03-02 Joseph S. Myers + + PR c/8927 + * gcc.dg/pr8927-1.c: New test. + 2005-03-01 Nathan Sidwell PR c++/20232 diff --git a/gcc/testsuite/gcc.dg/pr8927-1.c b/gcc/testsuite/gcc.dg/pr8927-1.c new file mode 100644 index 000000000000..218e71706ac7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr8927-1.c @@ -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" } */ + + + ; +}