OSDN Git Service

DR 337
authorgiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 10 Jan 2004 01:18:08 +0000 (01:18 +0000)
committergiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 10 Jan 2004 01:18:08 +0000 (01:18 +0000)
PR c++/9256
* pt.c (tsubst): Substitution must fail if we are attempting to
create an array with element type that is an abstract class type.
* decl.c (cp_finish_decl): Strip pointers and array types recursively
before calling abstract_virtuals_error.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75618 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/pt.c

index bdbdd36..3dc569c 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-10  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       DR 337
+       PR c++/9256
+       * pt.c (tsubst): Substitution must fail if we are attempting to 
+       create an array with element type that is an abstract class type.
+       * decl.c (cp_finish_decl): Strip pointers and array types recursively
+       before calling abstract_virtuals_error.
+
 2004-01-09  Alexandre Oliva  <aoliva@redhat.com>
 
        * name-lookup.c (qualified_lookup_using_namespace): Consider
index c7a294d..3ce6d0a 100644 (file)
@@ -4879,8 +4879,19 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
          || TREE_CODE (type) == METHOD_TYPE)
        abstract_virtuals_error (decl,
                                 strip_array_types (TREE_TYPE (type)));
+      else if (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
+      {
+       /* If it's either a pointer or an array type, strip through all
+          of them but the last one. If the last is an array type, issue 
+          an error if the element type is abstract.  */
+       while (POINTER_TYPE_P (TREE_TYPE (type)) 
+              || TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
+         type = TREE_TYPE (type);
+       if (TREE_CODE (type) == ARRAY_TYPE)
+         abstract_virtuals_error (decl, TREE_TYPE (type));
+      }
       else
-       abstract_virtuals_error (decl, strip_array_types (type));
+       abstract_virtuals_error (decl, type);
 
       if (TREE_CODE (decl) == FUNCTION_DECL 
          || TREE_TYPE (decl) == error_mark_node)
index 6b099a1..040476c 100644 (file)
@@ -6975,7 +6975,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
           The deduction may fail for any of the following reasons: 
 
           -- Attempting to create an array with an element type that
-             is void, a function type, or a reference type.  */
+             is void, a function type, or a reference type, or [DR337] 
+             an abstract class type.  */
        if (TREE_CODE (type) == VOID_TYPE 
            || TREE_CODE (type) == FUNCTION_TYPE
            || TREE_CODE (type) == REFERENCE_TYPE)
@@ -6984,6 +6985,13 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
              error ("creating array of `%T'", type);
            return error_mark_node;
          }
+       if (CLASS_TYPE_P (type) && CLASSTYPE_PURE_VIRTUALS (type))
+         {
+           if (complain & tf_error)
+             error ("creating array of `%T', which is an abstract class type", 
+                    type);
+           return error_mark_node;         
+         }
 
        r = build_cplus_array_type (type, domain);
        return r;