Commit 5bb2f1e7 by Mark Mitchell Committed by Mark Mitchell

tree.c (build_cplus_new): Adjust call to abstract_virtuals_error as per 1999-07-26 change.

	* 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
parent 4c8a3a89
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
......
*** 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")
......
......@@ -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);
......
......@@ -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));
}
......
// 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment