From patchwork Sat Aug 12 08:16:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gnaggnoyil X-Patchwork-Id: 134831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1589046vqi; Sat, 12 Aug 2023 01:17:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOao4hJpO3WYYxYSmm3fHxXkZqx93qNm88u3ACss+ZcyRWAtaBwQhLcwjkc1FkOI2AdOhd X-Received: by 2002:ac2:5f74:0:b0:4f5:1418:e230 with SMTP id c20-20020ac25f74000000b004f51418e230mr2829128lfc.52.1691828270374; Sat, 12 Aug 2023 01:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691828270; cv=none; d=google.com; s=arc-20160816; b=HNPhuxvKbC5zU6Ji0g1hRt8zjiPW+MdboRGnSX78qRu9N0HduuBwCUuBHq+lx6ILIQ YMpn21CI9E3OLl5Pxv5EBXHw2i9O4sjHbjl5OwOAZ0f/8RZ1FEvrWjyH+2WU6/NhvLLh b3wftKx/I+n/wIbz1AsauxItzzGWciHHEmEh7nzPy40tgAt6a1gcfw0mfso1WhhdK7MF CLHWURWobgOMQJSzNEWFTCtP14BMXDD5kXc9K4iSAXAEAOgietTvhJS/CbJ+evddrfhn QISNZtQDQH4jj6/SQ81ALfs1s7BegOa1BqF+iAUt99Eq9TZsm3KcEl/PI2wLXri+q8B9 lH8g== 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=T9N3qQWoqiPCuFsIarihlY4lzK+TNbIgI9j1gZI00r8=; fh=FvMqhgZLDd9hujdRO5Ok7RkVZI1SCD7xmKjyOAEBpgI=; b=nl2za9s9o98X+9uNTEQlG7bIxhoeNmkU16hBAdiG1Mbz/EDtclkXWnp2pS/exfKmKQ sQAD39XEejZbbvOa5zWBtG7WrwtL1mZLZgnexin0sBbGjCNpLbVWePp1+LWo5kCkBI9E +ETr3g3SKrXONShSo9XakwRsAjrG2LCad+3MLVqu+mpmcvPieqHSq3jZeS9NHgGThEK1 2oKn81/vZabpa1Fw17gLum4DPR7gMucVhWAgtG4vNDpuIogmjsFKQpP7uqNESK1UWJGI /EKs9QwhnJxJWZwj4OhUpueRHW+02qvxE/DqV3MbDuElyw7dNoY91KhlP2eHNINReRsA exOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U1llNMaB; 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 g20-20020a056402181400b005233889544esi4501182edy.135.2023.08.12.01.17.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Aug 2023 01:17:50 -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=U1llNMaB; 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 0F2FF3858D32 for ; Sat, 12 Aug 2023 08:17:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F2FF3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691828269; bh=T9N3qQWoqiPCuFsIarihlY4lzK+TNbIgI9j1gZI00r8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=U1llNMaBXMbM68UGNTJ9iqVILC/ll/OJu0+cToFyObWaLL1doc74FW8c18s//RfXs fhsRT4XxTv4TDiMlpJxMhcPxJ0GOZ2ivLlKp4IzWamg4vM+MNK7toSkItzKzFPopfq tTS3/MTWzCWGZuiENogXcnT0blvqYy/xGsG5b9Bo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id CD1833858D1E for ; Sat, 12 Aug 2023 08:17:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD1833858D1E Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-686f8614ce5so2536909b3a.3 for ; Sat, 12 Aug 2023 01:17:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691828223; x=1692433023; 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=T9N3qQWoqiPCuFsIarihlY4lzK+TNbIgI9j1gZI00r8=; b=ljROsrGl6hVKV+1eDsrfrR6C7NvW6wlEUEe3m3e1YLKMS4TL+k1ahG6GXlsdAzcObH 4xj9G2k7EZvebC8t6dZoLWsL4zd9tgVZNFP+sGbAlo/hCtq+cJbroDoqtJtmWCk2No4q XGJKIAzSwzfj+hsiQY1lKRs/D6CcVwskR3yG72SI23dly4vIFb5LJ3o6Yy/0erlj1MB/ tLxJIj3DlnYGU9HiViKZHmYrjraYmw5RzRaVEioFG/swdbcytFllnnOx1TwaiU1bU2W+ cDzeXfrhp8NH+S7UQx5z2C9tpTkZHCckE80HgIHQIaFyE3SKlGS2yXb3Ziv5LeIFiQk2 pujw== X-Gm-Message-State: AOJu0Yw/rwv+taW23V9S1+QZujV3IRrt4bj2spDq4I6zZVVygCGE7l86 ymo4kHX8mjCxKkTfIcLwWwNX7kZh94cSGT6p X-Received: by 2002:a05:6a21:339f:b0:140:6d68:ce07 with SMTP id yy31-20020a056a21339f00b001406d68ce07mr6252522pzb.52.1691828223510; Sat, 12 Aug 2023 01:17:03 -0700 (PDT) Received: from localhost ([2604:180:3:8e4::8d47]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b00687dde8ae5dsm4440939pfe.154.2023.08.12.01.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Aug 2023 01:17:03 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, polacek@redhat.com, gnaggnoyil Subject: [PATCH v1] c++: follow DR 2386 and update implementation of get_tuple_size [PR110216] Date: Sat, 12 Aug 2023 16:16:52 +0800 Message-ID: <20230812081652.1851216-1-gnaggnoyil@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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: 1774010520387512403 X-GMAIL-MSGID: 1774010520387512403 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/decomp10.C: Update expected error message for DR 2386. * g++.dg/cpp1z/pr110216.C: New test. Signed-off-by: gnaggnoyil --- Hi, As https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626696.html mentioned, I've updated the corresponding tests. I ran all tests in g++.dg and no unexpected fail exists now. gcc/cp/decl.cc | 6 +++++- gcc/testsuite/g++.dg/cpp1z/decomp10.C | 2 +- gcc/testsuite/g++.dg/cpp1z/pr110216.C | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) 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/decomp10.C b/gcc/testsuite/g++.dg/cpp1z/decomp10.C index f0723f8d85f..af83a79e781 100644 --- a/gcc/testsuite/g++.dg/cpp1z/decomp10.C +++ b/gcc/testsuite/g++.dg/cpp1z/decomp10.C @@ -7,7 +7,7 @@ namespace std { struct A1 { int i,j; } a1; template<> struct std::tuple_size { }; -void f1() { auto [ x ] = a1; } // { dg-error "is not an integral constant expression" } +void f1() { auto [ x ] = a1; } // { dg-error "only 1 name provided" } struct A2 { int i,j; } a2; template<> struct std::tuple_size { enum { value = 5 }; }; 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 () +{ +}