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>;
      |                   ^~~~

Reply via email to