+ quals = TYPE_QUALS (type);
+ /* METHOD and REFERENCE_TYPEs should never have quals. */
+ gcc_assert ((TREE_CODE (type) != METHOD_TYPE
+ && TREE_CODE (type) != REFERENCE_TYPE)
+ || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
+ == TYPE_UNQUALIFIED));
+ return quals;
+}
+
+/* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
+ METHOD_TYPE. */
+
+int
+type_memfn_quals (const_tree type)
+{
+ if (TREE_CODE (type) == FUNCTION_TYPE)
+ return TYPE_QUALS (type);
+ else if (TREE_CODE (type) == METHOD_TYPE)
+ return cp_type_quals (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))));
+ else
+ gcc_unreachable ();
+}
+
+/* Returns the FUNCTION_TYPE TYPE with its function-cv-quals changed to
+ MEMFN_QUALS. */
+
+tree
+apply_memfn_quals (tree type, cp_cv_quals memfn_quals)
+{
+ /* Could handle METHOD_TYPE here if necessary. */
+ gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
+ if (TYPE_QUALS (type) == memfn_quals)
+ return type;
+ /* This should really have a different TYPE_MAIN_VARIANT, but that gets
+ complex. */
+ return build_qualified_type (type, memfn_quals);