tree.c (build_cplus_new): Adjust call to abstract_virtuals_error as per 1999-07-26...
authorMark Mitchell <mark@codesourcery.com>
Tue, 27 Jul 1999 01:35:35 +0000 (01:35 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 27 Jul 1999 01:35:35 +0000 (01:35 +0000)
* tree.c (build_cplus_new): Adjust call to abstract_virtuals_error
as per 1999-07-26 change.

* typeck.c (c_sizeof): Don't allow non-static data members.
(expr_sizeof): Likewise.

From-SVN: r28280

gcc/cp/ChangeLog
gcc/cp/NEWS
gcc/cp/tree.c
gcc/cp/typeck.c
gcc/testsuite/g++.old-deja/g++.other/sizeof2.C [new file with mode: 0644]

index f9469a40dc4a39bc6dbc808f40e21a9e5d409eb6..b2e6c076b71da93b77eef49df97907ee66fbad8c 100644 (file)
@@ -1,3 +1,11 @@
+1999-07-26  Mark Mitchell  <mark@codesourcery.com>
+
+       * tree.c (build_cplus_new): Adjust call to abstract_virtuals_error
+       as per 1999-07-26 change.
+
+       * typeck.c (c_sizeof): Don't allow non-static data members.
+       (expr_sizeof): Likewise.
+
 1999-07-26  Jason Merrill  <jason@yorick.cygnus.com>
 
        * input.c (feed_input): Only touch lineno and input_filename
index 1a242abcf41c7089a74c08eb238cf8a9d0301b9c..89447970b02fa8314f8cfccb0047d9cf41e88019 100644 (file)
@@ -1,3 +1,20 @@
+*** Changes in GCC 3.0:
+
+* Certain invalid conversions that were previously accepted will now
+  be rejected.  For example, assigning function pointers of one type
+  to function pointers of another type now requires a cast, whereas
+  previously g++ would sometimes accept the code even without the
+  cast.
+
+* G++ previously allowed `sizeof (X::Y)' where Y was a non-static
+  member of X, even if the `sizeof' expression occurred outside
+  of a non-static member function of X (or one of its derived classes, 
+  or a member-initializer for X or one of its derived classes.)   This
+  extension has been removed.
+
+* G++ no longer allows you to overload the conditional operator (i.e., 
+  the `?:' operator.)
+
 *** Changes in GCC 2.95:
 
 * Messages about non-conformant code that we can still handle ("pedwarns")
index c32bf8f399e853c85e753546d5caafc8d16971e5..a84a9babe5dafafdd6a1ed2ef18cf673e2f78068 100644 (file)
@@ -226,8 +226,7 @@ build_cplus_new (type, init)
 
   /* Make sure that we're not trying to create an instance of an
      abstract class.  */
-  if (CLASSTYPE_ABSTRACT_VIRTUALS (type))
-    abstract_virtuals_error (NULL_TREE, type);
+  abstract_virtuals_error (NULL_TREE, type);
 
   if (TREE_CODE (init) != CALL_EXPR && TREE_CODE (init) != AGGR_INIT_EXPR)
     return convert (type, init);
index 64a6dadee12eaef9e4c69fca76799e409de43827..905b3e3a1b253bb959339f2651e139198f05cac1 100644 (file)
@@ -1603,16 +1603,6 @@ c_sizeof (type)
   if (code == REFERENCE_TYPE)
     type = TREE_TYPE (type);
 
-  /* We couldn't find anything in the ARM or the draft standard that says,
-     one way or the other, if doing sizeof on something that doesn't have
-     an object associated with it is correct or incorrect.  For example, if
-     you declare `struct S { char str[16]; };', and in your program do
-     a `sizeof (S::str)', should we flag that as an error or should we give
-     the size of it?  Since it seems like a reasonable thing to do, we'll go
-     with giving the value.  */
-  if (code == OFFSET_TYPE)
-    type = TREE_TYPE (type);
-
   /* @@ This also produces an error for a signature ref.
         In that case we should be able to do better.  */
   if (IS_SIGNATURE (type))
@@ -1620,6 +1610,11 @@ c_sizeof (type)
       error ("`sizeof' applied to a signature type");
       return size_int (0);
     }
+  else if (code == OFFSET_TYPE)
+    {
+      cp_error ("`sizeof' applied to non-static member");
+      return size_int (0);
+    }
 
   if (TYPE_SIZE (complete_type (type)) == 0)
     {
@@ -1665,6 +1660,15 @@ expr_sizeof (e)
       incomplete_type_error (e, TREE_TYPE (e));
       return size_int (1);
     }
+  /* It's illegal to say `sizeof (X::i)' for `i' a non-static data
+     member unless you're in a non-static member of X.  But, we used
+     to support this usage, so we still permit it unless we're being
+     pedantic.  */
+  else if (TREE_CODE (e) == OFFSET_REF)
+    e = resolve_offset_ref (e);
+
+  if (e == error_mark_node)
+    return e;
 
   return c_sizeof (TREE_TYPE (e));
 }
diff --git a/gcc/testsuite/g++.old-deja/g++.other/sizeof2.C b/gcc/testsuite/g++.old-deja/g++.other/sizeof2.C
new file mode 100644 (file)
index 0000000..c597844
--- /dev/null
@@ -0,0 +1,15 @@
+// Build don't link:
+// Origin: Mark Mitchell <mark@codesourcery.com>
+
+struct S
+{
+  int j; // ERROR - member
+  int i[2]; // ERROR - member
+};
+
+void f ()
+{
+  sizeof (S::j); // ERROR - non-static data member
+  sizeof (S::i[0]); //  ERROR - non-static data member
+}
+