From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E64B83858D33; Mon, 16 Jan 2023 09:35:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E64B83858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673861731; bh=eALmyLF0isKTlVV5Wz/87V5tjOyOb4f5U6lHtbujKaU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=b6wcBPomQT/eXE+Myy07uDmrIduvgUX9ly2VFpwi3JDMDRjblpfVdAvtc/2xADJx6 n0xweFS9u09wExWn9WuVtvn6ntblId9RZs0hdItndklXbZ5PybljLeigw2RKdmCrq2 V9hyF4RXPImaX8CDjYb3JnBMHfXHfb/lsZaIlkAg= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108414] template meta programming Date: Mon, 16 Jan 2023 09:35:31 +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: 12.2.0 X-Bugzilla-Keywords: c++-lambda, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned 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=3D108414 --- Comment #3 from Jonathan Wakely --- Reduced: using size_t =3D decltype(sizeof(0)); template struct type_identity { using type =3D T; }; template constexpr bool is_same_v =3D false; template constexpr bool is_same_v =3D true; template struct type_list {}; template struct indexed { using type =3D T; }; template struct indexer; template struct indexer : indexed, indexer {}; template struct indexer : indexed {}; template using nth_element_t =3D typename decltype([](const indexed&){return type_identity{};}(indexer<0, Ts...>{}))::type; template struct nth_type; template struct nth_type< I, type_list > { #ifndef USING typedef nth_element_t type; // Incorrect result with it #else using type =3D nth_element_t; // Compile error #endif }; template using nth_type_t =3D typename nth_type::type; using list =3D type_list; using elm0 =3D nth_type_t<0, list>; using elm1 =3D nth_type_t<1, list>; using elm2 =3D nth_type_t<2, list>; static_assert( is_same_v ); static_assert( is_same_v ); static_assert( is_same_v ); Without -DUSING nth.cc:47:16: error: static assertion failed 47 | static_assert( is_same_v ); | ^~~~~~~~~~~~~~~~~~~~~~ nth.cc:48:16: error: static assertion failed 48 | static_assert( is_same_v ); | ^~~~~~~~~~~~~~~~~~~~~~~ With -DUSING nth.cc: In substitution of 'template using nth_type_t =3D typename nth_type::type [with long unsigned int I =3D 0; T = =3D type_list]': nth.cc:42:32: required from here nth.cc:38:7: error: no type named 'type' in 'struct nth_type<0, type_list >' 38 | using nth_type_t =3D typename nth_type::type; | ^~~~~~~~~~ nth.cc: In substitution of 'template using nth_type_t =3D typename nth_type::type [with long unsigned int I =3D 1; T = =3D type_list]': nth.cc:43:32: required from here nth.cc:38:7: error: no type named 'type' in 'struct nth_type<1, type_list >' nth.cc: In substitution of 'template using nth_type_t =3D typename nth_type::type [with long unsigned int I =3D 2; T = =3D type_list]': nth.cc:44:32: required from here nth.cc:38:7: error: no type named 'type' in 'struct nth_type<2, type_list >' nth.cc:46:26: error: 'elm0' was not declared in this scope 46 | static_assert( is_same_v ); | ^~~~ nth.cc:46:16: error: template argument 1 is invalid 46 | static_assert( is_same_v ); | ^~~~~~~~~~~~~~~~~~~~ nth.cc:47:26: error: 'elm1' was not declared in this scope 47 | static_assert( is_same_v ); | ^~~~ nth.cc:47:16: error: template argument 1 is invalid 47 | static_assert( is_same_v ); | ^~~~~~~~~~~~~~~~~~~~~~ nth.cc:48:26: error: 'elm2' was not declared in this scope 48 | static_assert( is_same_v ); | ^~~~ nth.cc:48:16: error: template argument 1 is invalid 48 | static_assert( is_same_v ); | ^~~~~~~~~~~~~~~~~~~~~~~=