This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH, committed] Tweak abstract_virtual_errors to report the correct location


Hello,

this patch is part of my WIP patch for PR 2204, submitted here:
http://gcc.gnu.org/ml/gcc-patches/2004-02/msg00953.html

This part only affects abstract_virtual_errors(), and was already approved by
Gaby in a followup message. I have retested this separately on the current
mainline (i686-pc-linux-gnu), and I'm committing it.

Giovanni Bajo


cp/
        * typeck2.c (abstract_virtual_errors): Reword diagnostics, make them
        appear at the correct location.

testsuite/
        * g++.old-deja/g++.robertl/eb4.C: Adjust error markers.
        * g++.old-deja/g++.other/decl3.C: Likewise.


Index: cp/typeck2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck2.c,v
retrieving revision 1.158
diff -c -3 -p -r1.158 typeck2.c
*** cp/typeck2.c 13 May 2004 06:40:22 -0000 1.158
--- cp/typeck2.c 11 Jun 2004 01:25:24 -0000
*************** abstract_virtuals_error (tree decl, tree
*** 149,182 ****
   return 0;

        if (TREE_CODE (decl) == VAR_DECL)
!  error ("cannot declare variable `%D' to be of type `%T'",
!       decl, type);
        else if (TREE_CODE (decl) == PARM_DECL)
!  error ("cannot declare parameter `%D' to be of type `%T'",
!       decl, type);
        else if (TREE_CODE (decl) == FIELD_DECL)
!  error ("cannot declare field `%D' to be of type `%T'",
!       decl, type);
        else if (TREE_CODE (decl) == FUNCTION_DECL
          && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
!  error ("invalid return type for member function `%#D'", decl);
        else if (TREE_CODE (decl) == FUNCTION_DECL)
!  error ("invalid return type for function `%#D'", decl);
      }
    else
!     error ("cannot allocate an object of type `%T'", type);

    /* Only go through this once.  */
    if (TREE_PURPOSE (u) == NULL_TREE)
      {
        TREE_PURPOSE (u) = error_mark_node;

!       error ("  because the following virtual functions are abstract:");
        for (tu = u; tu; tu = TREE_CHAIN (tu))
!  cp_error_at ("\t%#D", TREE_VALUE (tu));
      }
    else
!     error ("  since type `%T' has abstract virtual functions", type);

    return 1;
  }
--- 149,189 ----
   return 0;

        if (TREE_CODE (decl) == VAR_DECL)
!  cp_error_at ("cannot declare variable `%+D' to be of abstract "
!        "type `%T'", decl, type);
        else if (TREE_CODE (decl) == PARM_DECL)
!  cp_error_at ("cannot declare parameter `%+D' to be of abstract "
!        "type `%T'", decl, type);
        else if (TREE_CODE (decl) == FIELD_DECL)
!  cp_error_at ("cannot declare field `%+D' to be of abstract "
!        "type `%T'", decl, type);
        else if (TREE_CODE (decl) == FUNCTION_DECL
          && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
!  cp_error_at ("invalid abstract return type for member function `%+#D'",
!        decl);
        else if (TREE_CODE (decl) == FUNCTION_DECL)
!  cp_error_at ("invalid abstract return type for function `%+#D'",
!        decl);
!       else
!  cp_error_at ("invalid abstract type for `%+D'", decl);
      }
    else
!     error ("cannot allocate an object of abstract type `%T'", type);

    /* Only go through this once.  */
    if (TREE_PURPOSE (u) == NULL_TREE)
      {
        TREE_PURPOSE (u) = error_mark_node;

!       inform ("%J  because the following virtual functions are pure "
!        "within `%T':", TYPE_MAIN_DECL (type), type);
!
        for (tu = u; tu; tu = TREE_CHAIN (tu))
!  inform ("%J\t%#D", TREE_VALUE (tu), TREE_VALUE (tu));
      }
    else
!     inform ("%J  since type `%T' has pure virtual functions",
!      TYPE_MAIN_DECL (type), type);

    return 1;
  }
Index: testsuite/g++.old-deja/g++.other/decl3.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/decl3.C,v
retrieving revision 1.4
diff -c -3 -p -r1.4 decl3.C
*** testsuite/g++.old-deja/g++.other/decl3.C 1 May 2003 02:02:49 -0000 1.4
--- testsuite/g++.old-deja/g++.other/decl3.C 11 Jun 2004 01:25:24 -0000
***************
*** 6,13 ****

  // We should not allow arrays of abstract type. [class.abstract/2]

! struct cow_t {
!   virtual void f()=0; // { dg-error "" } abstract
  };


--- 6,13 ----

  // We should not allow arrays of abstract type. [class.abstract/2]

! struct cow_t { // { dg-error "" } note
!   virtual void f()=0; // { dg-error "" } pure
  };


Index: testsuite/g++.old-deja/g++.robertl/eb4.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb4.C,v
retrieving revision 1.6
diff -c -3 -p -r1.6 eb4.C
*** testsuite/g++.old-deja/g++.robertl/eb4.C 1 May 2003 02:02:58 -0000 1.6
--- testsuite/g++.old-deja/g++.robertl/eb4.C 11 Jun 2004 01:25:24 -0000
*************** public:
*** 17,23 ****
          };

  class some_derived : public some_base
!         {
  public:
          class derived_func_args;
          void func(derived_func_args &);
--- 17,23 ----
          };

  class some_derived : public some_base
!         {  // { dg-error "" } note
  public:
          class derived_func_args;
          void func(derived_func_args &);



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]