public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/105518] New: [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias @ 2022-05-07 15:21 leventyilmaz at gmail dot com 2022-11-01 23:02 ` [Bug c++/105518] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: leventyilmaz at gmail dot com @ 2022-05-07 15:21 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105518 Bug ID: 105518 Summary: [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: leventyilmaz at gmail dot com Target Milestone: --- The following valid code is fails to compile. https://godbolt.org/z/v1sd9snGx // Simple run-time to compile-time integer conversion: template<class F> auto toStatic(int i, F f) { switch(i) { case 0: return f( std::integral_constant<int, 0>{} ); case 1: return f( std::integral_constant<int, 1>{} ); case 2: return f( std::integral_constant<int, 2>{} ); default: assert("too big"); } } // example types: struct Base { virtual void show() const = 0; }; template <size_t I> struct F { template <size_t J> struct K : Base { void show() const override { std::cout << I << " " << J << std::endl; } }; }; // nested lambda complains "I" is not captured // even though it is only being used at compile-time void show(int i, int j) { return toStatic(i, [j](auto I) { using A = F<I>; // using A = F<decltype(I)::value>; // this works return toStatic(j, [](auto J) { using impl = typename A::template K<J>; impl{}.show(); }); }); } source>:32:19: error: 'I' is not captured 32 | using impl = typename A::template K<J>; | ^~~~ ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105518] [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias 2022-05-07 15:21 [Bug c++/105518] New: [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias leventyilmaz at gmail dot com @ 2022-11-01 23:02 ` pinskia at gcc dot gnu.org 2022-12-15 20:54 ` cvs-commit at gcc dot gnu.org 2022-12-15 20:56 ` ppalka at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2022-11-01 23:02 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105518 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Created attachment 53819 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53819&action=edit full testcase ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105518] [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias 2022-05-07 15:21 [Bug c++/105518] New: [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias leventyilmaz at gmail dot com 2022-11-01 23:02 ` [Bug c++/105518] " pinskia at gcc dot gnu.org @ 2022-12-15 20:54 ` cvs-commit at gcc dot gnu.org 2022-12-15 20:56 ` ppalka at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2022-12-15 20:54 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105518 --- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:be124477b38a71ba8ba0b24d859ae764bb44a4eb commit r13-4729-gbe124477b38a71ba8ba0b24d859ae764bb44a4eb Author: Patrick Palka <ppalka@redhat.com> Date: Thu Dec 15 15:54:31 2022 -0500 c++: local alias in typename in lambda [PR105518] We substitute the qualifying scope of a TYPENAME_TYPE directly using tsubst_aggr_type (so that we can pass entering_scope=true) instead of going through tsubst, which means we don't properly reuse typedefs during this substitution. This ends up causing us to reject the below testcase because we substitute the TYPENAME_TYPE alias::type as if it were written without the A<t> alias, and thus we expect the non-capturing lambda to capture t. This patch fixes this by making tsubst_aggr_type delegate typedefs to tsubst so that get consistently reused, and then adjusting the result appropriately if entering_scope is true. In passing, this refactors tsubst_aggr_type into two functions, one that's intended to be called directly and a more minimal one that's intended to be called only from the RECORD/UNION/ENUMERAL_TYPE cases of tsubst (and contains only the necessary bits for that call site). PR c++/105518 gcc/cp/ChangeLog: * pt.cc (tsubst_aggr_type): Handle typedefs by delegating to tsubst and adjusting the result if entering_scope. Split out the main part of the function into ... (tsubst_aggr_type_1) ... here. (tsubst): Use tsubst_aggr_type_1 instead of tsubst_aggr_type. Handle TYPE_PTRMEMFUNC_P RECORD_TYPEs here instead of in tsubst_aggr_type_1. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-alias1.C: New test. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105518] [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias 2022-05-07 15:21 [Bug c++/105518] New: [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias leventyilmaz at gmail dot com 2022-11-01 23:02 ` [Bug c++/105518] " pinskia at gcc dot gnu.org 2022-12-15 20:54 ` cvs-commit at gcc dot gnu.org @ 2022-12-15 20:56 ` ppalka at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: ppalka at gcc dot gnu.org @ 2022-12-15 20:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105518 Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |13.0 Resolution|--- |FIXED Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org Status|UNCONFIRMED |RESOLVED CC| |ppalka at gcc dot gnu.org --- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> --- Fixed for GCC 13, thanks for the bug report. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-15 20:56 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-05-07 15:21 [Bug c++/105518] New: [rejects valid] nested lambda using an outer type alias fails with constexpr integer in that alias leventyilmaz at gmail dot com 2022-11-01 23:02 ` [Bug c++/105518] " pinskia at gcc dot gnu.org 2022-12-15 20:54 ` cvs-commit at gcc dot gnu.org 2022-12-15 20:56 ` ppalka at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).