From 7260f6f79cd3aea6580013d386ce0fd8696a6b19 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 6 Oct 2017 17:50:50 +0200 Subject: [PATCH] re PR c++/82299 (-Wuseless-cast errors on typed enums used in member data initializers in c++1z) PR c++/82299 * decl.c (reshape_init): Suppress warn_useless_cast for direct enum init. * typeck.c (convert_for_assignment): Likewise. * g++.dg/cpp0x/pr82299.C: New test. From-SVN: r253495 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 5 ++++- gcc/cp/typeck.c | 5 ++++- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp0x/pr82299.C | 9 +++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr82299.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e41576dddeb..ea0e8b6f9c8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2017-10-06 Jakub Jelinek + PR c++/82299 + * decl.c (reshape_init): Suppress warn_useless_cast for direct enum + init. + * typeck.c (convert_for_assignment): Likewise. + P0704R1 - fixing const-qualified pointers to members * typeck2.c (build_m_component_ref): For -std=c++2a allow pointer to const & qualified method on rvalue. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 7c68f68b9bd..6f36aa1a496 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6047,7 +6047,10 @@ reshape_init (tree type, tree init, tsubst_flags_t complain) tree elt = CONSTRUCTOR_ELT (init, 0)->value; type = cv_unqualified (type); if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain)) - return cp_build_c_cast (type, elt, tf_warning_or_error); + { + warning_sentinel w (warn_useless_cast); + return cp_build_c_cast (type, elt, tf_warning_or_error); + } else return error_mark_node; } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 326721eb5e0..c3310db7b3b 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8527,7 +8527,10 @@ convert_for_assignment (tree type, tree rhs, { tree elt = CONSTRUCTOR_ELT (rhs, 0)->value; if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain)) - rhs = cp_build_c_cast (type, elt, complain); + { + warning_sentinel w (warn_useless_cast); + rhs = cp_build_c_cast (type, elt, complain); + } else rhs = error_mark_node; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7432a3a46e8..d7af2a93b5a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-10-06 Jakub Jelinek + PR c++/82299 + * g++.dg/cpp0x/pr82299.C: New test. + P0704R1 - fixing const-qualified pointers to members * g++.dg/cpp2a/ptrmem1.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/pr82299.C b/gcc/testsuite/g++.dg/cpp0x/pr82299.C new file mode 100644 index 00000000000..27f4c5f6172 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr82299.C @@ -0,0 +1,9 @@ +// PR c++/82299 +// { dg-do compile { target c++11 } } +// { dg-options "-Wuseless-cast" } + +enum Enum : char { A = 0, B = 1 }; + +struct S { + Enum e { Enum::A }; // { dg-bogus "useless cast to type" } +}; -- 2.30.2