crash16.C: Function name is the correct location for an error regarding a function.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 15 Sep 2008 22:24:18 +0000 (22:24 +0000)
committerAldy Hernandez <aldyh@gcc.gnu.org>
Mon, 15 Sep 2008 22:24:18 +0000 (22:24 +0000)
testsuite/
        * g++.old-deja/g++.brendan/crash16.C: Function name is the correct
        location for an error regarding a function.
        * g++.old-deja/g++.other/pmf3.C: Same.
        * g++.old-deja/g++.law/ctors5.C: Same.
        * g++.old-deja/g++.pt/explicit34.C: Same.
        * g++.dg/parse/error28.C: Same.
        * g++.dg/parse/error17.C: Same.
        * g++.dg/template/friend44.C: Same.
cp/
        * decl.c (duplicate_decls): Call error_at.
        (grokfndecl): New location argument.  Use location if available.
        (grokdeclarator): Pass declarator location to grokfndecl.
        * cp-tree.h (struct cp_declarator): Update comment for id_loc.
        * decl2.c (check_classfn): Use error_at.
        * parser.c (cp_parser_init_declarator): Set function_start_locus
        to brace location.
        (cp_parser_member_declaration): Set id_loc for function declarators.

From-SVN: r140379

13 files changed:
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error17.C
gcc/testsuite/g++.dg/parse/error28.C
gcc/testsuite/g++.dg/template/friend44.C
gcc/testsuite/g++.old-deja/g++.brendan/crash16.C
gcc/testsuite/g++.old-deja/g++.law/ctors5.C
gcc/testsuite/g++.old-deja/g++.other/pmf3.C
gcc/testsuite/g++.old-deja/g++.pt/explicit34.C

index f455a32f07d26eb0157e537470e0bb4605c714da..5b36ffc1e9c127e9662295a68f39d88479c14a41 100644 (file)
@@ -1,3 +1,14 @@
+2008-09-15  Aldy Hernandez  <aldyh@redhat.com>
+
+       * decl.c (duplicate_decls): Call error_at.
+       (grokfndecl): New location argument.  Use location if available.
+       (grokdeclarator): Pass declarator location to grokfndecl.
+       * cp-tree.h (struct cp_declarator): Update comment for id_loc.
+       * decl2.c (check_classfn): Use error_at.
+       * parser.c (cp_parser_init_declarator): Set function_start_locus
+       to brace location.
+       (cp_parser_member_declaration): Set id_loc for function declarators.
+
 2008-09-09  Jan Hubicka  <jh@suse.cz>
 
        PR middle-end/37500
index a39e9da6975d92f64b0d47af9b956a9208d1169e..065e47de147308e15c94523dd0b7543f4ecf8a74 100644 (file)
@@ -4089,7 +4089,7 @@ struct cp_declarator {
   /* For all but cdk_id and cdk_error, the contained declarator.  For
      cdk_id and cdk_error, guaranteed to be NULL.  */
   cp_declarator *declarator;
-  location_t id_loc; /* Currently only set for cdk_id. */
+  location_t id_loc; /* Currently only set for cdk_id and cdk_function. */
   union {
     /* For identifiers.  */
     struct {
index d7c70182128e48313979a3d0bce112b2c41b6aaf..d699f89be32eb22ade8490d40f81987b432a4838 100644 (file)
@@ -1459,7 +1459,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
       if (errmsg)
        {
-         error (errmsg, newdecl);
+         error_at (DECL_SOURCE_LOCATION (newdecl), errmsg, newdecl);
          if (DECL_NAME (olddecl) != NULL_TREE)
            error ((DECL_INITIAL (olddecl) && namespace_bindings_p ())
                         ? "%q+#D previously defined here"
@@ -6497,7 +6497,8 @@ grokfndecl (tree ctype,
            bool funcdef_flag,
            int template_count,
            tree in_namespace,
-           tree* attrlist)
+           tree* attrlist,
+           location_t location)
 {
   tree decl;
   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
@@ -6507,6 +6508,12 @@ grokfndecl (tree ctype,
     type = build_exception_variant (type, raises);
 
   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
+
+  /* If we have an explicit location, use it, otherwise use whatever
+     build_lang_decl used (probably input_location).  */
+  if (location != UNKNOWN_LOCATION)
+    DECL_SOURCE_LOCATION (decl) = location;
+
   if (TREE_CODE (type) == METHOD_TYPE)
     {
       tree parm;
@@ -9018,7 +9025,8 @@ grokdeclarator (const cp_declarator *declarator,
                               virtualp, flags, memfn_quals, raises,
                               friendp ? -1 : 0, friendp, publicp, inlinep,
                               sfk,
-                              funcdef_flag, template_count, in_namespace, attrlist);
+                              funcdef_flag, template_count, in_namespace,
+                              attrlist, declarator->id_loc);
            if (decl == NULL_TREE)
              return error_mark_node;
 #if 0
@@ -9060,7 +9068,8 @@ grokdeclarator (const cp_declarator *declarator,
                               virtualp, flags, memfn_quals, raises,
                               friendp ? -1 : 0, friendp, 1, 0, sfk,
                               funcdef_flag, template_count, in_namespace,
-                              attrlist);
+                              attrlist,
+                              declarator->id_loc);
            if (decl == NULL_TREE)
              return error_mark_node;
          }
@@ -9255,7 +9264,8 @@ grokdeclarator (const cp_declarator *declarator,
                           virtualp, flags, memfn_quals, raises,
                           1, friendp,
                           publicp, inlinep, sfk, funcdef_flag,
-                          template_count, in_namespace, attrlist);
+                          template_count, in_namespace, attrlist,
+                          declarator->id_loc);
        if (decl == NULL_TREE)
          return error_mark_node;
 
index a128fb7c5e233a151ba4c1d422f09d041014c045..5aecf3c114c1e4a3aa06b08ae776c96ea5aaf431 100644 (file)
@@ -638,8 +638,9 @@ check_classfn (tree ctype, tree function, tree template_parms)
          return OVL_CURRENT (fndecls);
        }
       
-      error ("prototype for %q#D does not match any in class %qT",
-            function, ctype);
+      error_at (DECL_SOURCE_LOCATION (function),
+               "prototype for %q#D does not match any in class %qT",
+               function, ctype);
       is_conv_op = DECL_CONV_FN_P (fndecl);
 
       if (is_conv_op)
index 88f92e7ccc469a0d1efb00531adf7f251b7865eb..f28c76d9177926bb870d278b6cfdab2f59158bf8 100644 (file)
@@ -12563,6 +12563,9 @@ cp_parser_init_declarator (cp_parser* parser,
        }
       else
        {
+         location_t func_brace_location
+           = cp_lexer_peek_token (parser->lexer)->location;
+
          /* Neither attributes nor an asm-specification are allowed
             on a function-definition.  */
          if (asm_specification)
@@ -12586,6 +12589,13 @@ cp_parser_init_declarator (cp_parser* parser,
              = (cp_parser_function_definition_from_specifiers_and_declarator
                 (parser, decl_specifiers, prefix_attributes, declarator));
 
+         if (decl != error_mark_node && DECL_STRUCT_FUNCTION (decl))
+           {
+             /* This is where the prologue starts...  */
+             DECL_STRUCT_FUNCTION (decl)->function_start_locus
+               = func_brace_location;
+           }
+
          return decl;
        }
     }
@@ -15791,6 +15801,8 @@ cp_parser_member_declaration (cp_parser* parser)
                  return;
                }
              else
+               if (declarator->kind == cdk_function)
+                 declarator->id_loc = token->location;
                /* Create the declaration.  */
                decl = grokfield (declarator, &decl_specifiers,
                                  initializer, /*init_const_expr_p=*/true,
index 09b1972608757c5063c44336b67ee2487ce5ef5c..028862084d8eac493629b43bc1192b76c50fb588 100644 (file)
@@ -1,3 +1,14 @@
+2008-09-15  Aldy Hernandez  <aldyh@redhat.com>
+
+       * g++.old-deja/g++.brendan/crash16.C: Function name is the correct 
+       location for an error regarding a function.
+       * g++.old-deja/g++.other/pmf3.C: Same.
+       * g++.old-deja/g++.law/ctors5.C: Same.
+       * g++.old-deja/g++.pt/explicit34.C: Same.
+       * g++.dg/parse/error28.C: Same.
+       * g++.dg/parse/error17.C: Same.
+       * g++.dg/template/friend44.C: Same.
+
 2008-09-13  Raksit Ashok <raksit@google.com>
 
        PR rtl-optimization/37489
index 0e05217c04ddcf971b760e57ac7b632423c51d43..defd708982d95423e3d9071dfec2c128404ed183 100644 (file)
@@ -2,7 +2,7 @@
 // PR c++/16965
 
 template <typename T> struct B { 
-  static int Bar(T); // { dg-error "19: error: candidates are: |19: error:  " }
+  static int Bar(T); // { dg-error "14: error: candidates are: |14: error:  " }
 }; 
 struct D : B<int>, B<char> {}; 
  
index fd202a107672cb6b8527d3c1e9b58582c686d783..7162afa3a02074e2aab3fe9ba9bbec5955482544 100644 (file)
@@ -3,7 +3,7 @@
 
 struct virt { virt () {} virt (int i) {} };
 struct der : public virtual virt { // { dg-error "34: note:                 der::der" }
-  der (int i) : virt(i) {} // { dg-error "13: note: candidates are: der" }
+  der (int i) : virt(i) {} // { dg-error "3: note: candidates are: der" }
 };
 struct top : public der { 
   top () {} // { dg-bogus "der\\(const" }
index a0f63c866ae4fd67841efa00e8cccc4f8fccff15..04d68c3e0f0225ab5269b55c5abd5dc53373e34c 100644 (file)
@@ -1,8 +1,9 @@
+// { dg-options "-fshow-column" }
 //PR c++/28260
 
 template<int> struct A
 {
-  friend int foo(); // { dg-error "new declaration" }
+  friend int foo(); // { dg-error "14: error: new declaration" }
 };
 
-void foo() { A<0> a; } // { dg-error "ambiguates old declaration" } 
+void foo() { A<0> a; } // { dg-error "6: error: ambiguates old declaration" } 
index ddcae3c97cbedafa650678ff6e7517e695adfda8..d05c73b8015163448cd5b7d93aeeff21422199a0 100644 (file)
@@ -5,10 +5,10 @@
 class Graph { // { dg-error "1: error: new types|1: note: \\(perhaps" }
 public:
       unsigned         char N;
-      Graph(void) {} // { dg-error "17: error: 'Graph" }
+      Graph(void) {} // { dg-error "7: error: 'Graph" }
 }
 
-Graph::Graph(void) // { dg-error "18: error: return type|18: error: redefinition" }
+Graph::Graph(void) // { dg-error "18: error: return type|1: error: redefinition" }
 {    N = 10;
 }
 
index 1f469cf5d4945c2d2bcc97386aa4233889dd2e7e..c9851bf21b705be35285397dc395b3ceb7e13e13 100644 (file)
@@ -21,7 +21,7 @@ class Y // { dg-error "1: error: new types may not be defined in a return type|1
   public:
     Y();
 }
-X::X( int xi ) // { dg-error "14: error: return type specification for constructor invalid|14: note: candidates are: X::X\\(int\\)" }
+X::X( int xi ) // { dg-error "14: error: return type specification for constructor invalid|1: note: candidates are: X::X\\(int\\)" }
 {
     x = xi;
 }
index e5f757d07af4060eb022a57df32c5bb924994550..fa9e92ec99855865edbd484deed6ccac8f31aeac 100644 (file)
@@ -3,9 +3,9 @@
 // Bug: g++ was crashing after giving errors.
 
 template<class T>
-  void connect_to_method(
+  void connect_to_method( // { dg-error "candidates are" }
     T *receiver,
-    void (T::*method)()) // { dg-error "candidates are" }
+    void (T::*method)())
   {}
 
 class Gtk_Base
index 2841ff0525c47be2e272bcdf09b9b5f138c23f31..f90b4becb17d80b8a57ce1ba86adefc036ace0b9 100644 (file)
@@ -1,10 +1,11 @@
 // { dg-do assemble  }
+// { dg-options "-fshow-column" }
 // GROUPS passed templates
 template <class T>
 void foo(T t);
 
 template <>
-void foo(int) {}; // { dg-error "" } previously defined here.
+void foo(int) {}; // { dg-error "6:" } previously defined here.
 
 template <>
-void foo<int>(int) {} // { dg-error "" } duplicate specialization.
+void foo<int>(int) {} // { dg-error "6:" } duplicate specialization.