aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-04-07 17:46:48 -0400
committerJason Merrill <jason@gcc.gnu.org>2011-04-07 17:46:48 -0400
commit1ee44b260d206b5ebc51466d672adffcdcebf4f2 (patch)
tree52443856b69beaa5ce88f9b5f24330703dd3cf16 /gcc
parent39e7722bbfdce2277b92dd8d0df62399051c7c7a (diff)
downloadgcc-1ee44b260d206b5ebc51466d672adffcdcebf4f2.zip
gcc-1ee44b260d206b5ebc51466d672adffcdcebf4f2.tar.gz
gcc-1ee44b260d206b5ebc51466d672adffcdcebf4f2.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-common.c29
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/cvt.c8
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/enum9.C5
6 files changed, 46 insertions, 11 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index a7efe84..b859db6 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+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>
* c-target-def.h: New file.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 1252b18..e0acfea 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3939,16 +3939,25 @@ c_common_truthvalue_conversion (location_t location, tree expr)
}
CASE_CONVERT:
- /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
- since that affects how `default_conversion' will behave. */
- if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
- || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
- break;
- /* If this is widening the argument, we can ignore it. */
- if (TYPE_PRECISION (TREE_TYPE (expr))
- >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
- return c_common_truthvalue_conversion (location,
- TREE_OPERAND (expr, 0));
+ {
+ tree totype = TREE_TYPE (expr);
+ tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0));
+
+ /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
+ since that affects how `default_conversion' will behave. */
+ if (TREE_CODE (totype) == REFERENCE_TYPE
+ || TREE_CODE (fromtype) == REFERENCE_TYPE)
+ break;
+ /* 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;
case MODIFY_EXPR:
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 387677e..5ffe1f5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+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>
PR c++/48277
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 8ab0001..290b926 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -727,7 +727,13 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
return error_mark_node;
}
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));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1e572c7..dabb816 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2011-04-07 Jason Merrill <jason@redhat.com>
+
+ * g++.dg/cpp0x/enum9.C: New.
+
2011-04-07 Mike Stump <mikestump@comcast.net>
* gcc.dg/torture/stackalign/non-local-goto-5.c: Fix for targets
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum9.C b/gcc/testsuite/g++.dg/cpp0x/enum9.C
new file mode 100644
index 0000000..10e510b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum9.C
@@ -0,0 +1,5 @@
+// { dg-options -std=c++0x }
+
+enum class E { };
+E f();
+bool b2 = static_cast<bool>(f());