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
This commit is contained in:
parent
4a53d90b5f
commit
2d45625fa7
5 changed files with 101 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -1658,7 +1658,8 @@ 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",
|
||||
inform (input_location,
|
||||
" candidate conversions include %qD and %qD",
|
||||
winner, cand);
|
||||
}
|
||||
return error_mark_node;
|
||||
|
|
|
@ -12964,6 +12964,23 @@ build_enumerator (tree name, tree value, tree enumtype, location_t loc)
|
|||
if (! processing_template_decl)
|
||||
{
|
||||
/* Validate and default VALUE. */
|
||||
if (value != NULL_TREE)
|
||||
{
|
||||
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 (value == error_mark_node)
|
||||
value = NULL_TREE;
|
||||
|
||||
if (value != NULL_TREE)
|
||||
{
|
||||
value = cxx_constant_value (value);
|
||||
|
@ -12976,6 +12993,7 @@ build_enumerator (tree name, tree value, tree enumtype, location_t loc)
|
|||
value = NULL_TREE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Default based on previous value. */
|
||||
if (value == NULL_TREE)
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2014-08-07 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
PR c++/51312
|
||||
* g++.dg/cpp0x/enum29.C: New.
|
||||
|
||||
2014-08-07 John David Anglin <danglin@gcc.gnu.org>
|
||||
|
||||
* gcc.dg/atomic/c11-atomic-exec-4.c: Undefine _POSIX_C_SOURCE before
|
||||
|
|
58
gcc/testsuite/g++.dg/cpp0x/enum29.C
Normal file
58
gcc/testsuite/g++.dg/cpp0x/enum29.C
Normal file
|
@ -0,0 +1,58 @@
|
|||
// PR c++/51312
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
struct X0
|
||||
{
|
||||
constexpr operator int() const { return 1; }
|
||||
};
|
||||
|
||||
struct X1
|
||||
{
|
||||
enum RE1 { re1 = 1 };
|
||||
constexpr operator RE1() const { return re1; }
|
||||
};
|
||||
|
||||
struct X2
|
||||
{
|
||||
constexpr operator int() const { return __INT_MAX__; }
|
||||
};
|
||||
|
||||
struct X3
|
||||
{
|
||||
enum RE3 { re3 = __INT_MAX__ };
|
||||
constexpr operator RE3() const { return re3; }
|
||||
};
|
||||
|
||||
struct X4
|
||||
{
|
||||
constexpr operator double() const { return 1.0; }
|
||||
};
|
||||
|
||||
struct X5
|
||||
{
|
||||
constexpr operator int() const { return __INT_MAX__; }
|
||||
constexpr operator unsigned() const { return __INT_MAX__ * 2U + 1; }
|
||||
};
|
||||
|
||||
enum E0 { e0 = X0() };
|
||||
enum E1 { e1 = X1() };
|
||||
enum E2 { e2 = X2() };
|
||||
enum E3 { e3 = X3() };
|
||||
enum E4 { e4 = X4() }; // { dg-error "integer constant" }
|
||||
enum E5 { e5 = X5() }; // { dg-error "ambiguous" }
|
||||
|
||||
enum F0 : int { f0 = X0() };
|
||||
enum F1 : int { f1 = X1() };
|
||||
enum F2 : int { f2 = X2() };
|
||||
enum F3 : int { f3 = X3() };
|
||||
enum F4 : int { f4 = X4() }; // { dg-error "narrowing" }
|
||||
enum F5 : int { f5 = X5() };
|
||||
|
||||
enum G0 : signed char { g0 = X0() };
|
||||
enum G1 : signed char { g1 = X1() };
|
||||
enum G2 : signed char { g2 = X2() }; // { dg-error "narrowing" }
|
||||
// { dg-warning "overflow" "" { target *-*-* } 53 }
|
||||
enum G3 : signed char { g3 = X3() }; // { dg-error "narrowing" }
|
||||
// { dg-warning "overflow" "" { target *-*-* } 55 }
|
||||
enum G4 : signed char { g4 = X4() }; // { dg-error "narrowing" }
|
||||
enum G5 : signed char { g5 = X5() }; // { dg-error "ambiguous" }
|
Loading…
Add table
Reference in a new issue