From patchwork Thu Apr 22 14:49:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1469239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=BPLWCOKy; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR0hF59jDz9sVq for ; Fri, 23 Apr 2021 00:50:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E03D63896C14; Thu, 22 Apr 2021 14:50:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E03D63896C14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619103000; bh=JUV4ckXJYn2ue065m5L/BwpqvvIgFW6XDd5V0DSPD9E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BPLWCOKyYIWV1UL9Py6Y9MS5KvOrt4zRutKpek3OasYIL7OcPX4D/eIXwM4vH8o2S 284amhU1NP/BkpWnQM9d0ZuB2e9fICJJMobRxcHC/8dU5/SuJqkI/nlZJGLuKlehsQ g4ZvkB61ununSJKfQ8WyWssvfmCLKK4zvSXro2jc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 87D3D3894422 for ; Thu, 22 Apr 2021 14:49:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87D3D3894422 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-__TyoLOlNFa97qsEqjMeAQ-1; Thu, 22 Apr 2021 10:49:57 -0400 X-MC-Unique: __TyoLOlNFa97qsEqjMeAQ-1 Received: by mail-qt1-f200.google.com with SMTP id v1-20020a05622a1301b02901b8238285bbso10151377qtk.0 for ; Thu, 22 Apr 2021 07:49:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JUV4ckXJYn2ue065m5L/BwpqvvIgFW6XDd5V0DSPD9E=; b=aB3AHgy0Tx91HKfW9dX/cKeojo6BjFPUGd7dGyZ+POZgg5ZORX9nAUDTgtYZXU14Fq uX4lRKnYCerDf8itnkh2WNAvZ9s9yr2+y/1aw8M8ch/mu2StYlxNeLDuIotf3MRqa+Di xNIuZB1jeuIV4awHbM4FbXSdvjr3SUX/GAezaX4TuLyv/iMGv4lCVloBen9fGTvhmZn1 c6OSd7LMlkS3IUB1sI66jQzQ97R7PZA6v0BEJYnrmJbyIgjzX5cjVJAj5qqFfUfU5V3b d+GdoNfs40N3yVB7D+kwNXdX1bavY4dOVeYMhqxt/REPeGUh1fKGBGE7T2ajjYnVhWuA KSWQ== X-Gm-Message-State: AOAM532cMYBbVZpGGG79e5MdpddnnPuAclMpWCODzgbGTGS2UY7GMpBv WbhrHuJ6gxjDamXBxVSL3bjaXN0ecAFEMg9KwYtmx81sVCkc2k8FXTd7lVSTs5x1K5uB+of3rc7 1/NGrpNXAZFHF1lY1kKRmIFqwKVGyXSu+SsGMaE1244iWHbM1FA3/YK62xxglqD9X1PM= X-Received: by 2002:a37:7ec6:: with SMTP id z189mr3876967qkc.295.1619102996407; Thu, 22 Apr 2021 07:49:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoUo5sq478BuD39cjFXkNWoeHiEQND44idg4Qcrzx6EyNyvuu5XOl3+4/dlW2cFm+0kOY9FA== X-Received: by 2002:a37:7ec6:: with SMTP id z189mr3876944qkc.295.1619102996071; Thu, 22 Apr 2021 07:49:56 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id u184sm2308394qkd.82.2021.04.22.07.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 07:49:55 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Refine enum direct-list-initialization [CWG2374] Date: Thu, 22 Apr 2021 10:49:54 -0400 Message-Id: <20210422144954.2557181-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.1.362.g311531c9de MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This implements the wording changes of CWG2374, which clarifies the wording of P0138 to forbid e.g. direct-list-initialization of a scoped enumeration from a different scoped enumeration. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: DR 2374 * decl.c (is_direct_enum_init): Check the implicit convertibility requirement added by CWG 2374. gcc/testsuite/ChangeLog: DR 2374 * g++.dg/cpp1z/direct-enum-init2.C: New test. --- gcc/cp/decl.c | 8 +++++++- gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b81de8ef934..60dc2bf182d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6191,7 +6191,13 @@ is_direct_enum_init (tree type, tree init) && ENUM_FIXED_UNDERLYING_TYPE_P (type) && TREE_CODE (init) == CONSTRUCTOR && CONSTRUCTOR_IS_DIRECT_INIT (init) - && CONSTRUCTOR_NELTS (init) == 1) + && CONSTRUCTOR_NELTS (init) == 1 + /* DR 2374: The single element needs to be implicitly + convertible to the underlying type of the enum. */ + && can_convert_arg (ENUM_UNDERLYING_TYPE (type), + TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value), + CONSTRUCTOR_ELT (init, 0)->value, + LOOKUP_IMPLICIT, tf_none)) return true; return false; } diff --git a/gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C new file mode 100644 index 00000000000..5b94a8d00fe --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/direct-enum-init2.C @@ -0,0 +1,8 @@ +// DR 2374 +// { dg-do compile { target c++17 } } + +enum class Orange; +enum class Apple; + +extern Orange o; +Apple a{o}; // { dg-error "cannot convert" }