+2019-03-28 Marek Polacek <polacek@redhat.com>
+
+ PR c++/89836 - bool constant expression and explicit conversions.
+ * call.c (build_converted_constant_expr_internal): New function,
+ renamed from...
+ (build_converted_constant_expr): ...this. New.
+ (build_converted_constant_bool_expr): New.
+ * cp-tree.h (build_converted_constant_bool_expr): Declare.
+ * decl.c (build_explicit_specifier): Call
+ build_converted_constant_bool_expr.
+
2019-03-28 Jakub Jelinek <jakub@redhat.com>
PR c++/89785
return ret;
}
-/* Subroutine of convert_nontype_argument.
-
- EXPR is an expression used in a context that requires a converted
- constant-expression, such as a template non-type parameter. Do any
- necessary conversions (that are permitted for converted
- constant-expressions) to convert it to the desired type.
-
- If conversion is successful, returns the converted expression;
- otherwise, returns error_mark_node. */
+/* Worker for build_converted_constant_expr. */
-tree
-build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
+static tree
+build_converted_constant_expr_internal (tree type, tree expr,
+ int flags, tsubst_flags_t complain)
{
conversion *conv;
void *p;
p = conversion_obstack_alloc (0);
conv = implicit_conversion (type, TREE_TYPE (expr), expr,
- /*c_cast_p=*/false,
- LOOKUP_IMPLICIT, complain);
+ /*c_cast_p=*/false, flags, complain);
/* A converted constant expression of type T is an expression, implicitly
converted to type T, where the converted expression is a constant
return expr;
}
+/* Subroutine of convert_nontype_argument.
+
+ EXPR is an expression used in a context that requires a converted
+ constant-expression, such as a template non-type parameter. Do any
+ necessary conversions (that are permitted for converted
+ constant-expressions) to convert it to the desired type.
+
+ This function doesn't consider explicit conversion functions. If
+ you mean to use "a contextually converted constant expression of type
+ bool", use build_converted_constant_bool_expr.
+
+ If conversion is successful, returns the converted expression;
+ otherwise, returns error_mark_node. */
+
+tree
+build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
+{
+ return build_converted_constant_expr_internal (type, expr, LOOKUP_IMPLICIT,
+ complain);
+}
+
+/* Used to create "a contextually converted constant expression of type
+ bool". This differs from build_converted_constant_expr in that it
+ also considers explicit conversion functions. */
+
+tree
+build_converted_constant_bool_expr (tree expr, tsubst_flags_t complain)
+{
+ return build_converted_constant_expr_internal (boolean_type_node, expr,
+ LOOKUP_NORMAL, complain);
+}
+
/* Do any initial processing on the arguments to a function call. */
static vec<tree, va_gc> *
extern tree perform_implicit_conversion (tree, tree, tsubst_flags_t);
extern tree perform_implicit_conversion_flags (tree, tree, tsubst_flags_t, int);
extern tree build_converted_constant_expr (tree, tree, tsubst_flags_t);
+extern tree build_converted_constant_bool_expr (tree, tsubst_flags_t);
extern tree perform_direct_initialization_if_possible (tree, tree, bool,
tsubst_flags_t);
extern tree in_charge_arg_for_name (tree);