From patchwork Sun Aug 6 18:15:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gnaggnoyil X-Patchwork-Id: 131624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1039066vqr; Sun, 6 Aug 2023 11:16:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvmAu4gujSE0i4Rp49JG6+IEkQF/TLaB3kuLO6EQjGW2Fpy2FViH+jkbEamjnkFT/KtPf4 X-Received: by 2002:a17:907:75d9:b0:982:c8d0:683f with SMTP id jl25-20020a17090775d900b00982c8d0683fmr6778854ejc.18.1691345815803; Sun, 06 Aug 2023 11:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691345815; cv=none; d=google.com; s=arc-20160816; b=Rau6pMTSgkkL5OJPG2rutnTK2qPwNg7TIlND0qdKiyRIParc/qzOLnUgNZQnjYSrTm 2E0WmD8IlOc4Ia3jq1zK238E8O9pjM24GUu1K6sYHL3QXPT9kpUAfOWuccsoj+5yT/qc GuYL48Od8eqnBASGXbX/qnZ70W/QQP+bZr8IyRuYS7vICTEPJkcD/m775QYVqOSK+wVa H/7IyWcmXgIw3idi4s8ZyygGcna4XPNxK2Ro9FM2hkYPqm8JW+ppDnzmybRG9h3y77p2 cmMREIXbQJy87/JrE8mNZTpyx7Sc1BZioCbqKLkPGgbVL1nA9a8C9B9kZAv7warNd5pB +MFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=AqnZKsllodwcGCMSFUxDdCzHkc0dkvfad515VMoa4kQ=; fh=FvMqhgZLDd9hujdRO5Ok7RkVZI1SCD7xmKjyOAEBpgI=; b=eXtuNHyc6ZtH+q6CF2/Q9SR/wYIFZuCDF+EjGoQFrL4vdltN3DsP9e/L7dSqTpuf7Q 5iJjjPky3W/EmVmXd9P/swlque4YrEQIkm+Pp+pR0P2HnwHU3PZclQrI3TIZmAgbu9dZ X8LfgbYrJxEDgTZ7Skm4Ir69x+6FjQigGCBhbB+chju+FV+hWKu6KayFzE7heIhk0HqZ nyJ7t+33er/kzJh1vKhIKVd/vY3crnlud0lK3Qrz6Lcs1Sof6W8Nuz/o4e/kYYmVZ0UH SgRLLjSuMdMJu59QlBa2ilgRLCbyDmCR3rgpcYPgPFMFpOSgfgaC8JJDCpAQmuIWH/ss DC7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GX0iJAA5; 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=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d22-20020a170906175600b00992acf935aesi4667255eje.412.2023.08.06.11.16.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 11:16:55 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=GX0iJAA5; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C09A3858407 for ; Sun, 6 Aug 2023 18:16:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C09A3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691345814; bh=AqnZKsllodwcGCMSFUxDdCzHkc0dkvfad515VMoa4kQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GX0iJAA5JQyPLugIa+SyZrulZEIkufhVHfM8n7ZebBtbw/Y99+Z9bpx5uwxTxYwlf Es1WDDd2USIL9xTML7hmnhAgezf8XQX+8j4fd2pMWUYfnzgPG2/Onr9bTPoGfRECDq ruhYVbjWPcHgSS5Ub5EtjPYhD+lflHOGYS8c9/SE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 0A7CD3858D1E for ; Sun, 6 Aug 2023 18:16:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A7CD3858D1E Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686b643df5dso2546494b3a.1 for ; Sun, 06 Aug 2023 11:16:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691345772; x=1691950572; 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=AqnZKsllodwcGCMSFUxDdCzHkc0dkvfad515VMoa4kQ=; b=c2nsOILIUYqcvGr4M6ZBcjXB2FspOrwY03nWbDhfORATUMC9OwUmenC00d4/e8eUvs R8aMw9c0ZakafAUOp+jchDNegoZJRRKVR1dVWcUptpfjSj/KStLwaCJfcSB+RjE8zFCX 9e5ndf9GJUWz5TxoocHAmHdAM/lEHXBFB0OIpiehA0lmL3VCX/zDKqqKzOum9Qfdd8ee gOaUr5kCYGXiW5ucJVklNlF7nRwCyBk+HvFxpaTDxuA6aCgPaO3NB+cPbDRNHHo4y+j6 pK1pSLlCeeKcMe58IhOrE8hMH3iHk/aAINH1HzVtmIkExDnvuqg5phqKGDkkIc6ThoJ/ CQIw== X-Gm-Message-State: AOJu0YzHBIF/9jHigz9yhS79MwMmpWy+HVycai177f7TiHFAbtKeVbaR AMEKNv01nhFcYNUgmuX0QTJbEt2fZLHvJbMB X-Received: by 2002:a05:6a20:1441:b0:12f:eb74:72b6 with SMTP id a1-20020a056a20144100b0012feb7472b6mr7691453pzi.60.1691345771791; Sun, 06 Aug 2023 11:16:11 -0700 (PDT) Received: from localhost ([2604:180:3:8e4::8d47]) by smtp.gmail.com with ESMTPSA id y5-20020a1709029b8500b001b8943b37a5sm5201051plp.24.2023.08.06.11.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 11:16:11 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, polacek@redhat.com, gnaggnoyil Subject: [PATCH] c++: follow DR 2386 and update implementation of get_tuple_size [PR110216] Date: Mon, 7 Aug 2023 02:15:35 +0800 Message-ID: <20230806181535.71101-1-gnaggnoyil@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 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: gnaggnoyil via Gcc-patches From: gnaggnoyil Reply-To: gnaggnoyil Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773504630350489555 X-GMAIL-MSGID: 1773504630350489555 DR 2386 updated the tuple_size requirements for structured binding and it now requires tuple_size to be considered only if std::tuple_size names a complete class type with member value. GCC before this patch does not follow the updated requrements, and this patch is intended to implement it. DR 2386 PR c++/110216 gcc/cp/ChangeLog: * decl.cc (get_tuple_size): Update implemetation to follow DR 2386. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/pr110216.C: New test. Signed-off-by: Yonggang Li --- gcc/cp/decl.cc | 6 +++++- gcc/testsuite/g++.dg/cpp1z/pr110216.C | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/pr110216.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 792ab330dd0..923b81a33b0 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8940,10 +8940,14 @@ get_tuple_size (tree type) /*context*/std_node, /*entering_scope*/false, tf_none); inst = complete_type (inst); - if (inst == error_mark_node || !COMPLETE_TYPE_P (inst)) + if (inst == error_mark_node + || !COMPLETE_TYPE_P (inst) + || !CLASS_TYPE_P (type)) return NULL_TREE; tree val = lookup_qualified_name (inst, value_identifier, LOOK_want::NORMAL, /*complain*/false); + if (val == error_mark_node) + return NULL_TREE; if (VAR_P (val) || TREE_CODE (val) == CONST_DECL) val = maybe_constant_value (val); if (TREE_CODE (val) == INTEGER_CST) diff --git a/gcc/testsuite/g++.dg/cpp1z/pr110216.C b/gcc/testsuite/g++.dg/cpp1z/pr110216.C new file mode 100644 index 00000000000..be4fd5f7053 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/pr110216.C @@ -0,0 +1,21 @@ +// DR 2386 +// PR c++/110216 +// { dg-do compile { target c++17 } } + + +namespace std{ + template struct tuple_size; +} + +struct A { + int x = 0; +}; + +template <> struct std::tuple_size <::A> {}; + +auto [x] = A{}; + +int +main () +{ +}