diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-02-01 19:31:23 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-02-01 19:31:23 +0000 |
commit | 33d31608efaff0bcd06e6ee67a70fc46bbebf974 (patch) | |
tree | 80228c7e0490ef91806b6ba75498c7783a7abd06 /gcc/cp | |
parent | 11ce0f1a9b9c3a018744ebcda20e674b57a0be70 (diff) | |
download | gcc-33d31608efaff0bcd06e6ee67a70fc46bbebf974.tar.gz |
* typeck.c (build_component_ref): Always complain about offsetof
constructs on non-PODs. Only make it an error for members of
virtual bases.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49406 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 30 |
2 files changed, 30 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 63c87471241..af18329d129 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2002-02-01 Jason Merrill <jason@redhat.com> + * typeck.c (build_component_ref): Always complain about offsetof + constructs on non-PODs. Only make it an error for members of + virtual bases. + * error.c (dump_scope): Don't add TFF_DECL_SPECIFIERS. (dump_function_decl): Always dump parms. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 5e69b98fc9d..ba37b10fff6 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1999,6 +1999,8 @@ build_component_ref (datum, component, basetype_path, protect) register tree ref; tree field_type; int type_quals; + tree old_datum; + tree old_basetype; if (processing_template_decl) return build_min_nt (COMPONENT_REF, datum, component); @@ -2202,6 +2204,9 @@ build_component_ref (datum, component, basetype_path, protect) if (TREE_DEPRECATED (field)) warn_deprecated_use (field); + old_datum = datum; + old_basetype = basetype; + /* See if we have to do any conversions so that we pick up the field from the right context. */ if (DECL_FIELD_CONTEXT (field) != basetype) @@ -2215,12 +2220,17 @@ build_component_ref (datum, component, basetype_path, protect) /* Handle base classes here... */ if (base != basetype && TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (basetype)) { - tree binfo = lookup_base (TREE_TYPE (datum), base, ba_check, NULL); - + base_kind kind; + tree binfo = lookup_base (TREE_TYPE (datum), base, ba_check, &kind); + + /* Complain about use of offsetof which will break. */ if (TREE_CODE (datum) == INDIRECT_REF - && integer_zerop (TREE_OPERAND (datum, 0))) + && integer_zerop (TREE_OPERAND (datum, 0)) + && kind == bk_via_virtual) { - error ("invalid reference to NULL ptr, use ptr-to-member instead"); + error ("\ +invalid offsetof from non-POD type `%#T'; use pointer to member instead", + basetype); return error_mark_node; } datum = build_base_path (PLUS_EXPR, datum, binfo, 1); @@ -2239,6 +2249,18 @@ build_component_ref (datum, component, basetype_path, protect) } } + /* Complain about other invalid uses of offsetof, even though they will + give the right answer. Note that we complain whether or not they + actually used the offsetof macro, since there's no way to know at this + point. So we just give a warning, instead of a pedwarn. */ + if (protect + && CLASSTYPE_NON_POD_P (old_basetype) + && TREE_CODE (old_datum) == INDIRECT_REF + && integer_zerop (TREE_OPERAND (old_datum, 0))) + warning ("\ +invalid offsetof from non-POD type `%#T'; use pointer to member instead", + basetype); + /* Compute the type of the field, as described in [expr.ref]. */ type_quals = TYPE_UNQUALIFIED; field_type = TREE_TYPE (field); |