Previously, the CONSTP parameter was a weird mix of local state and
external configuration. It was valid to call the function with -1 or 1,
where -1 indicates that the function actually only returns true if
FROM had a proper subset of qualification compared to TO. The value 1
was used as an initial value to confirm that all outer layers were
const, and would be made zero if any value wasn't.
This patch splits this weird amalgamate, making the function instead
take PROPERP which, if set, instructs the function to return true only
if FROM is a proper subset of TO (as the -1 case before), and instead
tracking the outer constness via a local bool.
No functional changes intended.
gcc/cp/ChangeLog:
* typeck.cc (comp_ptr_ttypes_real): Update signature to take a
bool properp rather than a constp that's either 1 or -1, which
is then used in turn as local state.
(comp_cv_qual_signature): Call the above with true instead of -1
now.
(comp_ptr_ttypes): Call the above with false instead of 1 now.
---
gcc/cp/typeck.cc | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 170b90828868..43a04c7cbcf5 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -56,7 +56,7 @@ static tree cp_pointer_int_sum (location_t, enum tree_code,
tree, tree,
tsubst_flags_t);
static tree rationalize_conditional_expr (enum tree_code, tree,
tsubst_flags_t);
-static bool comp_ptr_ttypes_real (tree, tree, int);
+static bool comp_ptr_ttypes_real (tree, tree, bool);
static bool comp_except_types (tree, tree, bool);
static bool comp_array_types (const_tree, const_tree, compare_bounds_t, bool);
static tree pointer_diff (location_t, tree, tree, tree, tsubst_flags_t, tree
*);
@@ -2213,9 +2213,9 @@ comp_cv_qualification (const_tree type1, const_tree type2)
int
comp_cv_qual_signature (tree type1, tree type2)
{
- if (comp_ptr_ttypes_real (type2, type1, -1))
+ if (comp_ptr_ttypes_real (type2, type1, true))
return 1;
- else if (comp_ptr_ttypes_real (type1, type2, -1))
+ else if (comp_ptr_ttypes_real (type1, type2, true))
return -1;
else
return 0;
@@ -12116,20 +12116,20 @@ check_return_expr (tree retval, bool *no_warning,
bool *dangling)
/* Returns nonzero if the pointer-type FROM can be converted to the
- pointer-type TO via a qualification conversion. If CONSTP is -1,
- then we return nonzero if the pointers are similar, and the
- cv-qualification signature of FROM is a proper subset of that of TO.
-
- If CONSTP is positive, then all outer pointers have been
- const-qualified. */
+ pointer-type TO via a qualification conversion. If PROPERP, then we return
+ nonzero if the pointers are similar, and the cv-qualification signature of
+ FROM is a proper subset of that of TO. */
static bool
-comp_ptr_ttypes_real (tree to, tree from, int constp)
+comp_ptr_ttypes_real (tree to, tree from, bool properp)
{
bool to_more_cv_qualified = false;
bool is_opaque_pointer = false;
bool is_toplevel = true;
+ /* True if all the levels so far were const-qualified. */
+ bool outer_const = true;
+
for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from), is_toplevel = false)
{
if (TREE_CODE (to) != TREE_CODE (from))
@@ -12169,15 +12169,18 @@ comp_ptr_ttypes_real (tree to, tree from, int constp)
{
/* TO has extra qualifiers over FROM. Per [conv.qual]p3.3, this
is permitted only if the outer levels all had const ("const
- is added to every ..."). */
- if (constp == 0)
+ is added to every ...").
+
+ If PROPERP, the goal is to compare the qualification sets of
+ the pointers, so don't early-exit. */
+ if (!properp && !outer_const)
return false;
to_more_cv_qualified = true;
}
- if (constp > 0)
- constp &= TYPE_READONLY (to);
+ if (!TYPE_READONLY (to))
+ outer_const = false;
}
if (VECTOR_TYPE_P (to))
@@ -12194,7 +12197,7 @@ comp_ptr_ttypes_real (tree to, tree from, int constp)
&& !TYPE_PTRDATAMEM_P (to)
/* CWG 330 says we need to look through arrays. */
&& TREE_CODE (to) != ARRAY_TYPE)
- return ((constp >= 0 || to_more_cv_qualified)
+ return ((!properp || to_more_cv_qualified)
&& (is_opaque_pointer
|| same_type_ignoring_top_level_qualifiers_p (to, from)));
}
@@ -12207,7 +12210,7 @@ comp_ptr_ttypes_real (tree to, tree from, int constp)
int
comp_ptr_ttypes (tree to, tree from)
{
- return comp_ptr_ttypes_real (to, from, 1);
+ return comp_ptr_ttypes_real (to, from, false);
}
/* Returns true iff FNTYPE is a non-class type that involves
--
2.55.0