diff options
author | Jason Merrill <jason@redhat.com> | 2017-06-09 20:40:44 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-06-09 20:40:44 -0400 |
commit | 8b8b203a26bdac3dede77e76d06e4e7084f79acc (patch) | |
tree | 17fc780673ab6af72b41232e6ed5191e0b849c1d /gcc/cp/cvt.c | |
parent | 52486891929862f8272e1c602957f5cb3b5d6e2a (diff) | |
download | gcc-8b8b203a26bdac3dede77e76d06e4e7084f79acc.zip gcc-8b8b203a26bdac3dede77e76d06e4e7084f79acc.tar.gz gcc-8b8b203a26bdac3dede77e76d06e4e7084f79acc.tar.bz2 |
Overhaul pointer-to-member conversion and template argument handling.
* call.c (standard_conversion): Avoid creating ck_pmem when the
class type is the same.
* cvt.c (can_convert_qual): Split from
perform_qualification_conversions.
* constexpr.c (cxx_eval_constant_expression): Check it.
* typeck.c (convert_ptrmem): Only cplus_expand_constant if
adjustment is necessary.
* pt.c (check_valid_ptrmem_cst_expr): Compare class types.
(convert_nontype_argument): Avoid redundant error.
From-SVN: r249088
Diffstat (limited to 'gcc/cp/cvt.c')
-rw-r--r-- | gcc/cp/cvt.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 6b28ef6..3460e13 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1890,6 +1890,26 @@ type_promotes_to (tree type) closely. Although they are used only in pt.c at the moment, they should presumably be used everywhere in the future. */ +/* True iff EXPR can be converted to TYPE via a qualification conversion. + Callers should check for identical types before calling this function. */ + +bool +can_convert_qual (tree type, tree expr) +{ + tree expr_type = TREE_TYPE (expr); + gcc_assert (!same_type_p (type, expr_type)); + + if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type)) + return comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type)); + else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (expr_type)) + return (same_type_p (TYPE_PTRMEM_CLASS_TYPE (type), + TYPE_PTRMEM_CLASS_TYPE (expr_type)) + && comp_ptr_ttypes (TYPE_PTRMEM_POINTED_TO_TYPE (type), + TYPE_PTRMEM_POINTED_TO_TYPE (expr_type))); + else + return false; +} + /* Attempt to perform qualification conversions on EXPR to convert it to TYPE. Return the resulting expression, or error_mark_node if the conversion was impossible. */ @@ -1903,14 +1923,7 @@ perform_qualification_conversions (tree type, tree expr) if (same_type_p (type, expr_type)) return expr; - else if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type) - && comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type))) - return build_nop (type, expr); - else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (expr_type) - && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type), - TYPE_PTRMEM_CLASS_TYPE (expr_type)) - && comp_ptr_ttypes (TYPE_PTRMEM_POINTED_TO_TYPE (type), - TYPE_PTRMEM_POINTED_TO_TYPE (expr_type))) + else if (can_convert_qual (type, expr)) return build_nop (type, expr); else return error_mark_node; |