From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D83443858C2D for ; Tue, 24 Oct 2023 20:56:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D83443858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D83443858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698180979; cv=none; b=rnIFab1R/FnwddIqehkQmtOUImNQZtDd2Fp/Xuk+JQORMGPyAYAqn5nqumNzMGLcle16rQldwXURAg7M+ckMifKBG9YeECMIg2/GPV4Kil2Qs8W3mTpDp/d4h1VvTsH0MjCvyHllNJmhWP4WEaDxzcSassgEvyke3rhlFSWKyNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698180979; c=relaxed/simple; bh=BvKcfcFsNjcU1ebtZWnK3XV3HOg9XPt5jqeOvwpl8is=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UIYhu3nGiQb+jhCjd6cTLDQZXn7A+9aSxrIbv+k+NH/SCrhlHSJ33tFZ5K1iZzyhXbrRXRrzzTuk/4IrMvmP12UcJPuwxPLN2v+4OkwJtm/BQJsglTBUyLArysHAu3RtoxP4JETR7tkkPZNexegqy5som5tt7ELxLcIVbcCZBVg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698180977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xtfa/XF/H8vt8zIXrlAVdL+3yd6p0qyDGbQz00uL5BY=; b=NhiIDR9E4fDkUzhLvtrWEqZ6w2V+r5KKoX36/ZTvVPV8BsWoze3cH+cbcj2fTANB2nN4Sq Hi7ybJxDFLJdLji37h/hf1wi0hodONapPF6T6ulotLDDJDpJw3ceGfe548+g69DhsSPqVn bk8iSj+ZwGLbkFtNxTVuEvbW8xfMSkk= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-D-kVT5o2PjuQBfaicpDp_w-1; Tue, 24 Oct 2023 16:56:15 -0400 X-MC-Unique: D-kVT5o2PjuQBfaicpDp_w-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-66d155fc53eso69068096d6.1 for ; Tue, 24 Oct 2023 13:56:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698180975; x=1698785775; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xtfa/XF/H8vt8zIXrlAVdL+3yd6p0qyDGbQz00uL5BY=; b=fAXKC/aCP6Yhi4mzI5f39as/ZYDhhtMVN0yqJvxNXsqInOIJENqPGcwUE5CVis/8S7 +ip4Vi9mJXTsjbxeK0P9xcD47Ml5diN7DHYbAdSU5fbvbWMGd3obsTP8TOjugyB1J8/B CDBcJEl7SgqudS7pcnNy6tbzaSR2T+ItqzziuwbShs7RVG4NT5zjcAFiM/1CdS2OjnaX HLyjh8ApiTknZatlLoRh5WQV9ODITjncuztUyoItPL+dD+ZjweOw+zF0rgMrNvbIxakl wdYtJ0koC4rjMlDhe5GuZoqxepeQ83UMS5jOVKahwYo0AjyTkTgPtbsUZ7s1X3VY5d1T zNnQ== X-Gm-Message-State: AOJu0Yxert/HC2XcnMQ4tp+GlKCDovSiCVm9VUw/e4cAdxBsVAkusaCH x80uq6ednISwUafe6LZX3j0GrKaVzTBesyWImgRxupD+ryBgiA49dZg2ngre+2J+svgLRux1xHs 7gh0LB5axoW2IeBe5tG3aSjNtfQ== X-Received: by 2002:ad4:5746:0:b0:66d:86a7:d611 with SMTP id q6-20020ad45746000000b0066d86a7d611mr19238276qvx.50.1698180975183; Tue, 24 Oct 2023 13:56:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuPC5mX6BUuZjaKo99SJxEMWhohruvjKRoqs41lx7ww7t/o6PBklJ3gbaHprn/7UWQkLPgCQ== X-Received: by 2002:ad4:5746:0:b0:66d:86a7:d611 with SMTP id q6-20020ad45746000000b0066d86a7d611mr19238258qvx.50.1698180974863; Tue, 24 Oct 2023 13:56:14 -0700 (PDT) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id po15-20020a05620a384f00b007776c520488sm3699675qkn.9.2023.10.24.13.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 13:56:14 -0700 (PDT) Date: Tue, 24 Oct 2023 16:56:12 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] c++: error with bit-fields and scoped enums [PR111895] Message-ID: References: <20231024161843.20031-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Oct 24, 2023 at 04:46:02PM -0400, Jason Merrill wrote: > On 10/24/23 12:18, Marek Polacek wrote: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > -- >8 -- > > 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 . > > 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 > > will get us an expression whose type is the enum. (I thought we didn't > > need decay_conversion because that does a whole lot more but using it > > would make sense to me too.) > > It's possible that we might want some of that more, particularly > mark_rvalue_use; decay_conversion seems like the right answer. OK with that > change. Makes total sense, thank you. (I'd tested the version with decay_conversion and it worked fine.) > rvalue() would also make sense, though that seems to be missing a call to > unlowered_expr_type at the moment. In fact, after "otherwise, it's the > lvalue-to-rvalue conversion" in decay_conv should probably just be a call to > rvalue, with missing bits added to the latter function. Sounds good; I hope I'll get to it next week. I'm not going to make it part of this patch so that I can backport this one to 13 and leave the cleanup for trunk only. Marek