From: Mark Mitchell Date: Tue, 27 Jul 1999 01:35:35 +0000 (+0000) Subject: tree.c (build_cplus_new): Adjust call to abstract_virtuals_error as per 1999-07-26... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5bb2f1e70510b957105b09f31f4e11fff1347fca;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f9469a40dc4..b2e6c076b71 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +1999-07-26 Mark Mitchell + + * 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 * input.c (feed_input): Only touch lineno and input_filename diff --git a/gcc/cp/NEWS b/gcc/cp/NEWS index 1a242abcf41..89447970b02 100644 --- a/gcc/cp/NEWS +++ b/gcc/cp/NEWS @@ -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") diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index c32bf8f399e..a84a9babe5d 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -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); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 64a6dadee12..905b3e3a1b2 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 index 00000000000..c597844ae2e --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/sizeof2.C @@ -0,0 +1,15 @@ +// Build don't link: +// Origin: Mark Mitchell + +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 +} +