From patchwork Tue Nov 14 16:35:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 165018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2047611rwb; Tue, 14 Nov 2023 08:36:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXPy8K0NVilXL9BmwfL6h8zAZhQZnavnJeE9cYLOlfIeXKNrgUpBbaiGifaQoBfOqwVwI2 X-Received: by 2002:a05:620a:bd3:b0:778:969e:3a0c with SMTP id s19-20020a05620a0bd300b00778969e3a0cmr3793491qki.27.1699979790915; Tue, 14 Nov 2023 08:36:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699979790; cv=pass; d=google.com; s=arc-20160816; b=G+o2QB0at7a1xbxzYeF5mgSDc6l+FlUQULx6OenyGjhqy3m/dX8t/jyNfMCEmUbSwP ppkiCuFK6WOFf/qXqTQ8jZrRBKxQ5VGporaUqGb3c7HhDgsS5l9Ai3voV3HrJ45qu0jd pwxNaEikHoVb9DfwOjhwFyzYHZ048KAwJ54vQnt9fE92/dQg8Wfygdlc9hhVtWtNLNew RxDPTHVNh1jUPHmwU87C2nNuBn6i6nypBx7pRHHnv9MrkkMx6TUpQGNvCV9nMyrkSX27 Z5MdOvaBC2znKkWTz26dk9TwG/OpIds1u74cjgmxi7LX+k+iUKn3P8yMKgmjoVxK896M RdQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=R15SCuqrcpZ6YCQOilZS/H29tr4QwmSM1jLyI1dYMD4=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=CqE5/eKle1LMLebH//Up5otI6Gb73fxNEWOsRXySXhn7+QwgYqndYgu9lFXLs/avjI KxSRxCNf8oEyd522uqID9If5/7CTUhAz9qDmWxqWPYBvcCWSVNCcQJ+sVCTChMKj6srj EG4LcN69khQgRvKcJ42xHpegcWFGpTYw2zEuzaA1jm+NSa5x4egRLKkvsUSjJa9w2B1/ XxZIvmKs9mbX5hOn0pXo5hL4M6aMawaKrHTwgByRht8GEeVCwbNqZNJYkwyW/L0MnyEu J/oALesWok0mmUOMHXkJFh34HUXw8pXrfdrTZoA+rrkELqWkcIpcow/czlMQ3T7AtqN+ toFw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xpee35+X; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w4-20020a05620a444400b0077596c392f6si6841382qkp.630.2023.11.14.08.36.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 08:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xpee35+X; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D0AC3858413 for ; Tue, 14 Nov 2023 16:36:30 +0000 (GMT) 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BFCC33858D32 for ; Tue, 14 Nov 2023 16:35:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFCC33858D32 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 BFCC33858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699979744; cv=none; b=Bd114WEmeKJ80K1skvc3suZw7PI2rui7Db26Gl7U4c+7uhA2bw/6x70BeGNfqYl5evj1QPq1BTsv1rc8kVAJKtlljx+FuUr+KhfR+br4WCKm+UNCnnJaK0B+GcM0aNNqg2WmPIYkECwek+TwgjdSdmNooOig7YwBqzPUWziYtT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699979744; c=relaxed/simple; bh=49bQI5I2kfyREDPJJX0i4ZU8kkzodVs/bfwYHVDoXrU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JXlL9HiifboLr3cy6vSyFl4dKmYiqR3twmVs4XyjjXaBAh8SlWX89/GAsOg3L3P7ghht8LiU4jQEIcmvekJqA+G08t1KO5rYdy3rW2OHYz3JFvCYKdmg3Au/XW+YkT/AsWQTmg+kQYGIbE2t+tc3MYd+mmLx8L7ocaaFeowDJgA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699979741; 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: content-transfer-encoding:content-transfer-encoding; bh=R15SCuqrcpZ6YCQOilZS/H29tr4QwmSM1jLyI1dYMD4=; b=Xpee35+X7xDdAGgYIcw9Z4GMNIY35T7YaaDpd1LUyc5QcoRkD9mvzdsDfQNhLzTsQpnAGu xfPpOgbbL8hmwhFhM3d1tejhiUXmg5px8Rp9ag/4b+oVSMwhlgLth7n43uJTELuLAdCEva imv5H7v8c0ZCzWtTKHlUM98InS/PLDM= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-4mAI7ydoPWS44QQCIZKdDw-1; Tue, 14 Nov 2023 11:35:39 -0500 X-MC-Unique: 4mAI7ydoPWS44QQCIZKdDw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-778b5445527so1091050585a.1 for ; Tue, 14 Nov 2023 08:35:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979738; x=1700584538; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R15SCuqrcpZ6YCQOilZS/H29tr4QwmSM1jLyI1dYMD4=; b=f5VgNb6TUxTR0nWcoxpVfthHUeyw35Fl7tHCNlqsCNWpUmv4CSah3v/QVh9xidyTUP mgJl7aAHmY/0PZ3gxlyTE31ZAolaP0T6ahS591ZN4eM8k0f/EYiPepmErB83PIJnDqNW PyX7tKSudKdWBblQKWS6NwFiBShhYzS9FjKfmmerVu+EzL9R0K6rVkOth6P7lpetzdxD 8gM71lMeYe5NdCJEASfQ9oSYtSpAfpEfhHxDW90NkP6gTEiispMYSN+HNir483DaWq7b TJFgUYkl3ROOyuZSkSiRiOrp2UvPMKIkgR6wY2+/0yYixnNTOWSvwCG/aTkI5m4mknj0 uqnA== X-Gm-Message-State: AOJu0YxDHgQNX7v/SLDmtQv73S2X7uQEuzmZfSV8hiMnggCBr5Pvz9tF RIdm8GJj8c9hIKNkaG2gk6vXMRG79dzihUwmXlF93o3pn9yatZNWbzuDttb0X8+JaEQlrS6wSnM 1xWLlOqSKT4l66TIte8UKdHhK2DPLmwRpB0mB9tWf7MT/4canh4RVmd8ZzIKUtI0YsbCk+Who0S E= X-Received: by 2002:a05:620a:2910:b0:774:21d8:b0bb with SMTP id m16-20020a05620a291000b0077421d8b0bbmr4240457qkp.24.1699979738365; Tue, 14 Nov 2023 08:35:38 -0800 (PST) X-Received: by 2002:a05:620a:2910:b0:774:21d8:b0bb with SMTP id m16-20020a05620a291000b0077421d8b0bbmr4240427qkp.24.1699979737936; Tue, 14 Nov 2023 08:35:37 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f8-20020a05620a280800b0076ceb5eb309sm769822qkp.74.2023.11.14.08.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 08:35:37 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: direct enum init from type-dep elt [PR112515] Date: Tue, 14 Nov 2023 11:35:36 -0500 Message-ID: <20231114163536.1208039-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782558009308708931 X-GMAIL-MSGID: 1782558009308708931 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- The NON_DEPENDENT_EXPR removal exposed that is_direct_enum_init may end up checking convertibility of a type-dependent argument. PR c++/112515 gcc/cp/ChangeLog: * decl.cc (is_direct_enum_init): Return false if the single element is type-dependent. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent30.C: New test. --- gcc/cp/decl.cc | 1 + gcc/testsuite/g++.dg/template/non-dependent30.C | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent30.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 4a07c7e879b..4be4847810a 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6614,6 +6614,7 @@ is_direct_enum_init (tree type, tree init) && CONSTRUCTOR_NELTS (init) == 1 /* DR 2374: The single element needs to be implicitly convertible to the underlying type of the enum. */ + && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value) && can_convert_arg (ENUM_UNDERLYING_TYPE (type), TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value), CONSTRUCTOR_ELT (init, 0)->value, diff --git a/gcc/testsuite/g++.dg/template/non-dependent30.C b/gcc/testsuite/g++.dg/template/non-dependent30.C new file mode 100644 index 00000000000..32d48e44c09 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent30.C @@ -0,0 +1,9 @@ +// PR c++/112515 +// { dg-do compile { target c++11 } } + +enum E : int { }; + +template +E f(T t) { + return E{t.e}; +}