aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2014-08-07 19:51:28 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2014-08-07 19:51:28 +0000
commit2d45625fa77114876f0069ceb12c105721b38331 (patch)
treef8d388592ee3f6aa02f7d7dfeb975b4d0305f9a0 /gcc/cp
parent4a53d90b5fa1d6db71b2c9d384a74c88c3d2b58b (diff)
downloadgcc-2d45625fa77114876f0069ceb12c105721b38331.zip
gcc-2d45625fa77114876f0069ceb12c105721b38331.tar.gz
gcc-2d45625fa77114876f0069ceb12c105721b38331.tar.bz2
re PR c++/51312 ([C++0x] Wrong interpretation of converted constant expressions (for enumerator initializers))
/cp 2014-08-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/51312 * decl.c (build_enumerator): Handle class types with conversion operators via perform_implicit_conversion_flags and build_expr_type_conversion. * cvt.c (build_expr_type_conversion): Replace pair of errors with error + inform. /testsuite 2014-08-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/51312 * g++.dg/cpp0x/enum29.C: New. From-SVN: r213736
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/cvt.c5
-rw-r--r--gcc/cp/decl.c30
3 files changed, 37 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 38e8dae..0e70c5f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+2014-08-07 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/51312
+ * decl.c (build_enumerator): Handle class types with conversion
+ operators via perform_implicit_conversion_flags and
+ build_expr_type_conversion.
+
+ * cvt.c (build_expr_type_conversion): Replace pair of errors
+ with error + inform.
+
2014-08-07 Jason Merrill <jason@redhat.com>
PR c++/62043
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 1dec9cc..7be4f31 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1658,8 +1658,9 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
{
error ("ambiguous default type conversion from %qT",
basetype);
- error (" candidate conversions include %qD and %qD",
- winner, cand);
+ inform (input_location,
+ " candidate conversions include %qD and %qD",
+ winner, cand);
}
return error_mark_node;
}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index acc1192..bb6135b 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12966,14 +12966,32 @@ build_enumerator (tree name, tree value, tree enumtype, location_t loc)
/* Validate and default VALUE. */
if (value != NULL_TREE)
{
- value = cxx_constant_value (value);
+ if (!ENUM_UNDERLYING_TYPE (enumtype))
+ {
+ tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
+ value, true);
+ if (tmp_value)
+ value = tmp_value;
+ }
+ else if (! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
+ value = perform_implicit_conversion_flags
+ (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
+ LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
- if (TREE_CODE (value) != INTEGER_CST
- || ! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
+ if (value == error_mark_node)
+ value = NULL_TREE;
+
+ if (value != NULL_TREE)
{
- error ("enumerator value for %qD is not an integer constant",
- name);
- value = NULL_TREE;
+ value = cxx_constant_value (value);
+
+ if (TREE_CODE (value) != INTEGER_CST
+ || ! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
+ {
+ error ("enumerator value for %qD is not an integer constant",
+ name);
+ value = NULL_TREE;
+ }
}
}