public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111895] error: invalid operands of types 'unsigned char:2' and 'int' to binary 'operator!=' on enum class bitfield cast to bool Date: Wed, 25 Oct 2023 00:23:34 +0000 [thread overview] Message-ID: <bug-111895-4-n4G8c9o2NE@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-111895-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111895 --- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:6fa7284e2824310bb7204d41b5243c677ecb62d3 commit r14-4902-g6fa7284e2824310bb7204d41b5243c677ecb62d3 Author: Marek Polacek <polacek@redhat.com> Date: Mon Oct 23 17:06:45 2023 -0400 c++: error with bit-fields and scoped enums [PR111895] Here we issue a bogus error: invalid operands of types 'unsigned char:2' and 'int' to binary 'operator!=' when casting a bit-field of scoped enum type to bool. In build_static_cast_1, perform_direct_initialization_if_possible returns NULL_TREE, because the invented declaration T t(e) fails, which is correct. So we go down to ocp_convert, which has code to deal with this case: /* 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 = build_nop (ENUM_UNDERLYING_TYPE (intype), e); but the SCOPED_ENUM_P is false since intype is <unnamed-unsigned:2>. This could be fixed by using unlowered_expr_type. But then c_common_truthvalue_conversion/CASE_CONVERT has a similar problem, and unlowered_expr_type is a C++-only function. Rather than adding a dummy unlowered_expr_type to C, I think we should follow [expr.static.cast]p3: "the lvalue-to-rvalue conversion is applied to the bit-field and the resulting prvalue is used as the operand of the static_cast." There are no prvalue bit-fields, so the l-to-r conversion performed in decay_conversion will get us an expression whose type is the enum. PR c++/111895 gcc/cp/ChangeLog: * typeck.cc (build_static_cast_1): Call decay_conversion. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/scoped_enum12.C: New test.
next prev parent reply other threads:[~2023-10-25 0:23 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-20 14:05 [Bug c++/111895] New: error: invalid operands of types 'unsigned char:2' and 'int' to binary 'operator!=' nabijaczleweli at nabijaczleweli dot xyz 2023-10-20 15:19 ` [Bug c++/111895] error: invalid operands of types 'unsigned char:2' and 'int' to binary 'operator!=' on enum class bitfield cast to bool redi at gcc dot gnu.org 2023-10-20 22:08 ` mpolacek at gcc dot gnu.org 2023-10-23 20:34 ` mpolacek at gcc dot gnu.org 2023-10-25 0:23 ` cvs-commit at gcc dot gnu.org [this message] 2024-02-01 22:20 ` mpolacek at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-111895-4-n4G8c9o2NE@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).