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] [PR13927] Dump alias_decl and fix duplicated error message (regression 3.4/mainline)


Hello,

this patch makes error.c handle ALIAS_DECL just any other simple declartion,
thus fixing the diagnostic messages. It also removes a duplicated error message
in case of redefinition of a symbol of different kind: in fact
supplement_binding has the correct logic to handle this case, while
duplicate_decls was trying to be smart and doing the work itself.

Notice that the position at which the previous declaration is reported is wrong
(since it's at the end of the union). This is a different bug, I've xfailed it.

Tested on i686-pc-linux-gnu with no new regressions, OK for mainline and 3.4?

Giovanni Bajo



2004-02-02  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/13927
        * error.c (dump_decl) <ALIAS_DECL>: Dump as simple declarations.
        * decl.c (duplicate_decl): Don't try to emit an error message in
        case of different symbols.

2004-02-02  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/13927
        * g++.dg/other/error8.C: New test.


Index: error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/error.c,v
retrieving revision 1.241
diff -c -3 -p -r1.241 error.c
*** error.c 21 Dec 2003 21:07:30 -0000 1.241
--- error.c 2 Feb 2004 19:23:39 -0000
*************** dump_decl (tree t, int flags)
*** 791,796 ****
--- 791,797 ----
        /* Else fall through.  */
      case FIELD_DECL:
      case PARM_DECL:
+     case ALIAS_DECL:
        dump_simple_decl (t, TREE_TYPE (t), flags);
        break;

Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1175
diff -c -3 -p -r1.1175 decl.c
*** decl.c 17 Jan 2004 18:59:44 -0000 1.1175
--- decl.c 2 Feb 2004 19:24:03 -0000
*************** duplicate_decls (tree newdecl, tree oldd
*** 1290,1327 ****
      }
    else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
      {
!       if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl)
!     && TREE_CODE (newdecl) != TYPE_DECL
!     && ! (TREE_CODE (newdecl) == TEMPLATE_DECL
!    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL))
!    || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl)
!        && TREE_CODE (olddecl) != TYPE_DECL
!        && ! (TREE_CODE (olddecl) == TEMPLATE_DECL
!       && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
!    == TYPE_DECL))))
!  {
!    /* We do nothing special here, because C++ does such nasty
!       things with TYPE_DECLs.  Instead, just let the TYPE_DECL
!       get shadowed, and know that if we need to find a TYPE_DECL
!       for a given name, we can look in the IDENTIFIER_TYPE_VALUE
!       slot of the identifier.  */
!    return NULL_TREE;
!  }
!
!       if ((TREE_CODE (newdecl) == FUNCTION_DECL
!     && DECL_FUNCTION_TEMPLATE_P (olddecl))
!    || (TREE_CODE (olddecl) == FUNCTION_DECL
!        && DECL_FUNCTION_TEMPLATE_P (newdecl)))
!  return NULL_TREE;
!
!       error ("`%#D' redeclared as different kind of symbol", newdecl);
!       if (TREE_CODE (olddecl) == TREE_LIST)
!  olddecl = TREE_VALUE (olddecl);
!       cp_error_at ("previous declaration of `%#D'", olddecl);
!
!       /* New decl is completely inconsistent with the old one =>
!   tell caller to replace the old one.  */
!
        return NULL_TREE;
      }
    else if (!types_match)
--- 1290,1298 ----
      }
    else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
      {
!       /* It's a redeclaration as a different kind of symbol. Don't emit
!           an error message here: it will be emitted while binding the name
!           to the scope, if it's really invalid.  */
        return NULL_TREE;
      }
    else if (!types_match)



// { dg-do compile }
// Contributed by: Michael Elizabeth Chastain
//   <mec dot gnu at mindspring dot com>
// PR c++/13927: Wrong error message for redeclartion of type from union

void foo(void)
{
  union { int alpha; int beta; }; // { dg-error "previous declaration `int
alpha'" }
  double alpha;  // { dg-error "declaration of" }
}

// This checks both the templated version, and the position of the diagnostic
//  (which is currently wrong).
template <int>
void tfoo(void)
{
  union {
    int alpha;  // { dg-error "previous declaration `int alpha'" "" { xfail
*-*-* } }
    int beta;
  }; // { dg-bogus "" "misplaced position of the declaration" { xfail *-*-* } }
  double alpha; // { dg-error "declaration of" }
}




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