re PR c/8927 (Gcc give error for wrong line of C code.)
authorJoseph Myers <joseph@codesourcery.com>
Wed, 2 Mar 2005 02:50:25 +0000 (02:50 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 2 Mar 2005 02:50:25 +0000 (02:50 +0000)
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

gcc/ChangeLog
gcc/c-decl.c
gcc/c-parser.c
gcc/c-tree.h
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr8927-1.c [new file with mode: 0644]

index d4309b595031ee908c1a85c5b9fd4e1e7beaf842..46f4c118758db7db178cd8a2c1596f031926489a 100644 (file)
@@ -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
index 690d3b3bc8018c34a8d2ff23e196696f03afa466..5cad16ee69fe21688b8e55cc95d7c777620c4ba6 100644 (file)
@@ -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;
        }
 
index de6999a0add40cadd683de15a379747f8ecfe66e..e08f436b46e4d9d754f30180754e23c0a64ef405 100644 (file)
@@ -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;
index d16d6a6892d4286eddbeb6d4f0aa70ca80f84a2f..18b2634c1b7403590d46575c2fcc911f9af1d92c 100644 (file)
@@ -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 *);
index 3a38d22923b5554221758a8b0989f9c18f8cd382..ea1c81c7435a366aced690e6aa6447a1aab13c89 100644 (file)
@@ -1787,9 +1787,10 @@ build_array_ref (tree array, tree index)
 }
 \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);
@@ -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;
     }
 
index 5e3ceaa2078c78f08cba298d180367fee1d793db..d72534301c68f514bc8786a01578b4aaa2f28613 100644 (file)
@@ -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
diff --git a/gcc/testsuite/gcc.dg/pr8927-1.c b/gcc/testsuite/gcc.dg/pr8927-1.c
new file mode 100644 (file)
index 0000000..218e717
--- /dev/null
@@ -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" } */
+
+
+  ;
+}