Commit 1ee44b26 by Jason Merrill Committed by Jason Merrill

re PR c++/48450 ([C++0x][SFINAE] Hard errors with static_cast expressions)

	PR c++/48450
	* c-family/c-common.c (c_common_truthvalue_conversion): Don't ignore
	conversion from C++0x scoped enum.
	* cp/cvt.c (ocp_convert): Handle converting scoped enum to bool.

From-SVN: r172138
parent 39e7722b
2011-04-07 Jason Merrill <jason@redhat.com>
PR c++/48450
* c-common.c (c_common_truthvalue_conversion): Don't ignore
conversion from C++0x scoped enum.
2011-04-06 Joseph Myers <joseph@codesourcery.com> 2011-04-06 Joseph Myers <joseph@codesourcery.com>
* c-target-def.h: New file. * c-target-def.h: New file.
......
...@@ -3939,16 +3939,25 @@ c_common_truthvalue_conversion (location_t location, tree expr) ...@@ -3939,16 +3939,25 @@ c_common_truthvalue_conversion (location_t location, tree expr)
} }
CASE_CONVERT: CASE_CONVERT:
/* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, {
since that affects how `default_conversion' will behave. */ tree totype = TREE_TYPE (expr);
if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0));
|| TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
break; /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
/* If this is widening the argument, we can ignore it. */ since that affects how `default_conversion' will behave. */
if (TYPE_PRECISION (TREE_TYPE (expr)) if (TREE_CODE (totype) == REFERENCE_TYPE
>= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))) || TREE_CODE (fromtype) == REFERENCE_TYPE)
return c_common_truthvalue_conversion (location, break;
TREE_OPERAND (expr, 0)); /* Don't strip a conversion from C++0x scoped enum, since they
don't implicitly convert to other types. */
if (TREE_CODE (fromtype) == ENUMERAL_TYPE
&& ENUM_IS_SCOPED (fromtype))
break;
/* If this isn't narrowing the argument, we can ignore it. */
if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype))
return c_common_truthvalue_conversion (location,
TREE_OPERAND (expr, 0));
}
break; break;
case MODIFY_EXPR: case MODIFY_EXPR:
......
2011-04-07 Jason Merrill <jason@redhat.com>
PR c++/48450
* cvt.c (ocp_convert): Handle converting scoped enum to bool.
2011-03-31 Jason Merrill <jason@redhat.com> 2011-03-31 Jason Merrill <jason@redhat.com>
PR c++/48277 PR c++/48277
......
...@@ -727,7 +727,13 @@ ocp_convert (tree type, tree expr, int convtype, int flags) ...@@ -727,7 +727,13 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
return error_mark_node; return error_mark_node;
} }
if (code == BOOLEAN_TYPE) if (code == BOOLEAN_TYPE)
return cp_truthvalue_conversion (e); {
/* We can't implicitly convert a scoped enum to bool, so convert
to the underlying type first. */
if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
e = convert (ENUM_UNDERLYING_TYPE (intype), e);
return cp_truthvalue_conversion (e);
}
converted = fold_if_not_in_template (convert_to_integer (type, e)); converted = fold_if_not_in_template (convert_to_integer (type, e));
......
2011-04-07 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/enum9.C: New.
2011-04-07 Mike Stump <mikestump@comcast.net> 2011-04-07 Mike Stump <mikestump@comcast.net>
* gcc.dg/torture/stackalign/non-local-goto-5.c: Fix for targets * gcc.dg/torture/stackalign/non-local-goto-5.c: Fix for targets
......
// { dg-options -std=c++0x }
enum class E { };
E f();
bool b2 = static_cast<bool>(f());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment