From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9E7483858408; Fri, 1 Mar 2024 16:28:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E7483858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709310499; bh=z9/LZDXRf/fqIm3YL2XBeRA+AX3HZrvJFiUtE7ZoKs0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LY3TUfrMzSIXpxGUv2PFTjnfUqXgWJ9JY0T+P5bSiD1FfkAaja6pDet2Erg6GGWRi OWkARMJtN4aJOWmJJpU8FZ3gc0Zh6UJ/KVqYeeTirQoK8eswWQqNo1CGqZWTDpQN+7 xBASAVnyb+BPO/ZeMUgVUT2diNUeCyRHeeZfrLiE= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/92687] decltype of a structured binding to a tuple component is a reference type inside a template function Date: Fri, 01 Mar 2024 16:28:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.2.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D92687 --- Comment #6 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:867cbadb912ab75d0eaf919a3f992595e508482b commit r14-9258-g867cbadb912ab75d0eaf919a3f992595e508482b Author: Jakub Jelinek Date: Fri Mar 1 16:59:08 2024 +0100 c++: Fix up decltype of non-dependent structured binding decl in templa= te [PR92687] finish_decltype_type uses DECL_HAS_VALUE_EXPR_P (expr) check for DECL_DECOMPOSITION_P (expr) to determine if it is array/struct/vector/complex etc. subobject proxy case vs. structured binding using std::tuple_{size,element}. For non-templates or when templates are already instantiated, that works correctly, finalized DECL_DECOMPOSITION_P non-base vars indeed have DECL_VALUE_EXPR in the former case and don't have it in the latter. It works fine for dependent structured bindings as well, cp_finish_deco= mp in that case creates DECLTYPE_TYPE tree and defers the handling until instantiation. As the testcase shows, this doesn't work for the non-dependent structur= ed binding case in templates, because DECL_HAS_VALUE_EXPR_P is set in that case always; cp_finish_decomp ends with: if (processing_template_decl) { for (unsigned int i =3D 0; i < count; i++) if (!DECL_HAS_VALUE_EXPR_P (v[i])) { tree a =3D build_nt (ARRAY_REF, decl, size_int (i), NULL_TREE, NULL_TREE); SET_DECL_VALUE_EXPR (v[i], a); DECL_HAS_VALUE_EXPR_P (v[i]) =3D 1; } } and those artificial ARRAY_REFs are used in various places during instantiation to find out what base the DECL_DECOMPOSITION_P VAR_DECLs have and their positions. The following patch fixes that by changing lookup_decomp_type, such that it doesn't ICE when called on a DECL_DECOMPOSITION_P var which isn't in= a hash table, but returns NULL_TREE in that case, and for processing_template_decl asserts DECL_HAS_VALUE_EXPR_P is non-NULL and just calls lookup_decomp_type. If it returns non-NULL, it is a structured binding using tuple and its result is returned, otherwise it falls through to returning unlowered_expr_type (expr) because it is an array, structure etc. subobject proxy. For !processing_template_decl it keeps doing what it did before, DECL_HAS_VALUE_EXPR_P meaning it is an array/structure etc. subobject proxy, otherwise the tuple case. 2024-03-01 Jakub Jelinek PR c++/92687 * decl.cc (lookup_decomp_type): Return NULL_TREE if decomp_type_table doesn't have entry for V. * semantics.cc (finish_decltype_type): If ptds.saved, assert DECL_HAS_VALUE_EXPR_P is true and decide on tuple vs. non-tuple based on if lookup_decomp_type is NULL or not. * g++.dg/cpp1z/decomp59.C: New test.=