]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (grokdeclarator): Tighten checks for invalid destructors.
authorMark Mitchell <mark@markmitchell.com>
Mon, 9 Nov 1998 09:32:06 +0000 (09:32 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 9 Nov 1998 09:32:06 +0000 (09:32 +0000)
        * decl.c (grokdeclarator): Tighten checks for invalid
destructors.  Improve error-messages and error-recovery.
* decl2.c (check_classfn): Don't assume that mangled destructor
names contain type information.
 ----------------------------------------------------------------------

From-SVN: r23583

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c

index 9c3e7284269b01ac055c94a3a6f55ca449b37995..bc24d5ce6e08431ca1662dc540d64e27733f981c 100644 (file)
@@ -1,3 +1,10 @@
+1998-11-08  Mark Mitchell  <mark@markmitchell.com>
+
+       * decl.c (grokdeclarator): Tighten checks for invalid
+       destructors.  Improve error-messages and error-recovery.
+       * decl2.c (check_classfn): Don't assume that mangled destructor 
+       names contain type information.
+
 1998-11-02  Jason Merrill  <jason@yorick.cygnus.com>
 
        * decl2.c (import_export_decl): Call import_export_class.
index 92b19dc87b201be1aa50d92e06824a0039e0a75a..68f62ae5dcc7334a7cff08380832892af6999435 100644 (file)
@@ -9425,8 +9425,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
                      error ("destructor cannot be static member function");
                    if (quals)
                      {
-                       error ("destructors cannot be declared `const' or `volatile'");
-                       return void_type_node;
+                       cp_error ("destructors may not be `%s'",
+                                 IDENTIFIER_POINTER (TREE_VALUE (quals)));
+                       quals = NULL_TREE;
                      }
                    if (decl_context == FIELD)
                      {
@@ -9451,8 +9452,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
                      }
                    if (quals)
                      {
-                       error ("constructors cannot be declared `const' or `volatile'");
-                       return void_type_node;
+                       cp_error ("constructors may not be `%s'",
+                                 IDENTIFIER_POINTER (TREE_VALUE (quals)));
+                       quals = NULL_TREE;
                      }
                    {
                      RID_BIT_TYPE tmp_bits;
@@ -9510,24 +9512,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
 
            arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
 
-           if (declarator)
+           if (declarator && flags == DTOR_FLAG)
              {
-               /* Get past destructors, etc.
-                  We know we have one because FLAGS will be non-zero.
-
-                  Complain about improper parameter lists here.  */
+               /* A destructor declared in the body of a class will
+                  be represented as a BIT_NOT_EXPR.  But, we just
+                  want the underlying IDENTIFIER.  */
                if (TREE_CODE (declarator) == BIT_NOT_EXPR)
+                 declarator = TREE_OPERAND (declarator, 0);
+               
+               if (strict_prototype == 0 && arg_types == NULL_TREE)
+                 arg_types = void_list_node;
+               else if (arg_types == NULL_TREE
+                        || arg_types != void_list_node)
                  {
-                   declarator = TREE_OPERAND (declarator, 0);
-
-                   if (strict_prototype == 0 && arg_types == NULL_TREE)
-                     arg_types = void_list_node;
-                   else if (arg_types == NULL_TREE
-                            || arg_types != void_list_node)
-                     {
-                       error ("destructors cannot be specified with parameters");
-                       arg_types = void_list_node;
-                     }
+                   cp_error ("destructors may not have parameters");
+                   arg_types = void_list_node;
+                   last_function_parms = NULL_TREE;
                  }
              }
 
index baae04b2d401f18cc36b0e1c497025c5fb1419c7..903da7639904886c7b6db3f3a95310892bca501e 100644 (file)
@@ -1480,9 +1480,12 @@ check_classfn (ctype, function)
                  fndecl = OVL_CURRENT (fndecls);
                  /* The DECL_ASSEMBLER_NAME for a TEMPLATE_DECL is
                     not mangled, so the check below does not work
-                    correctly in that case.  */
+                    correctly in that case.  Since mangled destructor names
+                    do not include the type of the arguments, we
+                    can't use this short-cut for them, either.  */
                  if (TREE_CODE (function) != TEMPLATE_DECL
                      && TREE_CODE (fndecl) != TEMPLATE_DECL
+                     && !DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function))
                      && (DECL_ASSEMBLER_NAME (function) 
                          == DECL_ASSEMBLER_NAME (fndecl)))
                    return fndecl;