diff options
author | Nathan Sidwell <nathan@acm.org> | 1999-12-20 15:53:43 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 1999-12-20 15:53:43 +0000 |
commit | 6816f04063a29a51f23898e8fde845a5ddffe822 (patch) | |
tree | e8ad976331ce00676f70265e10ce93bcd0d9244d /gcc/cp | |
parent | 01d939e8fb624ea88487fd41ce93c238a5eb870a (diff) | |
download | gcc-6816f04063a29a51f23898e8fde845a5ddffe822.zip gcc-6816f04063a29a51f23898e8fde845a5ddffe822.tar.gz gcc-6816f04063a29a51f23898e8fde845a5ddffe822.tar.bz2 |
typeck.c (strip_all_pointer_quals): New static function.
* typeck.c (strip_all_pointer_quals): New static function.
(build_static_cast): Use it. Don't use at_least_as_qualified_p.
From-SVN: r31034
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 26 |
2 files changed, 24 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 73cfd67..8c67559 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +1999-12-20 Nathan Sidwell <nathan@acm.org> + + * typeck.c (strip_all_pointer_quals): New static function. + (build_static_cast): Use it. Don't use at_least_as_qualified_p. + 1999-12-16 Mark Mitchell <mark@codesourcery.com> * cp-tree.h (cp_tree_index): Add CPTI_DSO_HANDLE. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 8fb5179..ee12ee6 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -65,6 +65,7 @@ static int comp_cv_target_types PROTO((tree, tree, int)); static void casts_away_constness_r PROTO((tree *, tree *)); static int casts_away_constness PROTO ((tree, tree)); static void maybe_warn_about_returning_address_of_local PROTO ((tree)); +static tree strip_all_pointer_quals PROTO ((tree)); /* Return the target type of TYPE, which means return T for: T*, T&, T[], T (...), and otherwise, just T. */ @@ -5182,14 +5183,13 @@ build_static_cast (type, expr) /* FIXME handle casting to array type. */ ok = 0; - if (can_convert_arg (type, intype, expr)) + if (can_convert_arg (strip_all_pointer_quals (type), + strip_all_pointer_quals (intype), expr)) ok = 1; else if (TYPE_PTROB_P (type) && TYPE_PTROB_P (intype)) { tree binfo; if (IS_AGGR_TYPE (TREE_TYPE (type)) && IS_AGGR_TYPE (TREE_TYPE (intype)) - && at_least_as_qualified_p (TREE_TYPE (type), - TREE_TYPE (intype)) && (binfo = get_binfo (TREE_TYPE (intype), TREE_TYPE (type), 0)) && ! TREE_VIA_VIRTUAL (binfo)) ok = 1; @@ -5198,8 +5198,6 @@ build_static_cast (type, expr) { if (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))), TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (intype)))) - && at_least_as_qualified_p (TREE_TYPE (TREE_TYPE (type)), - TREE_TYPE (TREE_TYPE (intype))) && (binfo = get_binfo (TYPE_OFFSET_BASETYPE (TREE_TYPE (type)), TYPE_OFFSET_BASETYPE (TREE_TYPE (intype)), 0)) && ! TREE_VIA_VIRTUAL (binfo)) @@ -5208,13 +5206,13 @@ build_static_cast (type, expr) else if (TREE_CODE (intype) != BOOLEAN_TYPE && TREE_CODE (type) != ARRAY_TYPE && TREE_CODE (type) != FUNCTION_TYPE - && can_convert (intype, type)) + && can_convert (intype, strip_all_pointer_quals (type))) ok = 1; /* [expr.static.cast] The static_cast operator shall not be used to cast away - constnes. */ + constness. */ if (ok && casts_away_constness (intype, type)) { cp_error ("static_cast from `%T' to `%T' casts away constness", @@ -7173,3 +7171,17 @@ casts_away_constness (t1, t2) return 0; } + +/* Returns TYPE with its cv qualifiers removed + TYPE is T cv* .. *cv where T is not a pointer type, + returns T * .. * */ + +static tree +strip_all_pointer_quals (type) + tree type; +{ + if (TREE_CODE (type) == POINTER_TYPE) + return build_pointer_type (strip_all_pointer_quals (TREE_TYPE (type))); + else + return strip_top_quals (type); +} |