https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125715

            Bug ID: 125715
           Summary: ICE in code involving a lambda with "deducing this"
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bisqwit at iki dot fi
  Target Milestone: ---

The attached code produces this error:

GCC 14:

    sample.cc: In lambda function:
    sample.cc:27:17: internal compiler error: Segmentation fault
       27 |                 layers.emplace_back(activator);
          |                 ^~~~~~
    0x7f4b280b3e2f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
    0x7f4b2809cf76 __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
    0x7f4b2809d026 __libc_start_main_impl
        ../csu/libc-start.c:360
    Please submit a full bug report, with preprocessed source (by using
-freport-bug).
    Please include the complete backtrace with any bug report.
    See <file:///usr/share/doc/gcc-14/README.Bugs> for instructions.

GCC 15:

    sample.cc: In instantiation of ‘Network::Network(std::size_t, auto:6&& ...)
requires  sizeof ... ((Network::__ct ::args ...)) >= 2 [with auto:6 = {long
unsigned int, Sigmoid, long unsigned int, Sigm
    sample.cc:38:115:   required from here
       38 |                   Height*Width*2, Sigmoid(), Height*Width,
Sigmoid(), Height*Width, Sigmoid(), Height*4, Sigmoid());
          |                                                                    
                                              ^
    sample.cc:27:17: internal compiler error: in lookup_template_class, at
cp/pt.cc:10438
       27 |                 layers.emplace_back(activator);
          |                 ^~~~~~
    0x7ffa9fb9bf76 __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
    0x7ffa9fb9c026 __libc_start_main_impl
        ../csu/libc-start.c:360
    Please submit a full bug report, with preprocessed source (by using
-freport-bug).
    Please include the complete backtrace with any bug report.
    See <file:///usr/share/doc/gcc-15/README.Bugs> for instructions.



Compiler options:

    -c -std=c++23 -O0 -g
    Happens on all optimization levels, whether -g is included or not, with or
without warning flags
    Standard levels c++26, c++23, and c++20 (with warning)

Tested versions:

    g++-14 (Debian 14.3.0-14) 14.3.0
    g++-15 (Debian 15.2.0-17) 15.2.0

Tested on system:

    Debian testing rolling release
    Architecture: x86_64

Code:

    #include <vector>

    template<double defaultp, double(*const F)(double , double , double,
double)>
    struct func_base
    {
        const double alfa = defaultp, beta = defaultp;
    };
    static inline double sigmoid (double x, double y = 0, double alfa=0, double
beta=0)
    {
      return -x;
    }
    struct Sigmoid: public func_base<0., sigmoid>
    {
    };
    struct Network
    {
        struct Layer
        {
            Sigmoid sig;
        };
        std::vector<Layer> layers;

        Network(std::size_t input_size, auto&&... args)
requires(sizeof...(args) >= 2) : layers{}
        {
            auto AddLayers = [&](this auto& recurse, std::size_t prev_size,
std::size_t size, Sigmoid&& activator, auto&&... args2)
            {
                layers.emplace_back(activator);
                if constexpr(sizeof...(args2)) recurse(size,
std::forward<decltype(args2)>(args2)...);
            };
            AddLayers(input_size, std::forward<decltype(args)>(args)...);
        }
    };

    int main()
    {
        constexpr std::size_t Width=10, Height=7;
        Network test(Width*Height,
                  Height*Width*2, Sigmoid(), Height*Width, Sigmoid(),
Height*Width, Sigmoid(), Height*4, Sigmoid());
    }

Reply via email to