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

            Bug ID: 88557
           Summary: Lambda in template parameter list compiler
                    segmentation fault (ICE)
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vittorio.romeo at outlook dot com
  Target Milestone: ---

The following code

    template<int = []{ return 0; }()>
    void f() { }

causes an internal compiler error on gcc 9.x version 20181218:

    <source>: In lambda function:
    <source>:1:31: error: invalid use of 'auto'
        1 |     template<int = []{ return 0; }()>
          |                               ^
    <source>:1:31: error: could not convert '0' from 'int' to 'auto'
    <source>: At global scope:
    <source>:1:20: error: use of '<lambda()>' before deduction of 'auto'
        1 |     template<int = []{ return 0; }()>
          |                    ^~~~~~~~~~~~~~~
    <source>: In static member function 'static auto<lambda()>::_FUN()':
    <source>:1:20: error: invalid use of 'auto'
    <source>: At global scope:
    <source>:1:36: internal compiler error: Segmentation fault
        1 |     template<int = []{ return 0; }()>
          |                                    ^

Live example on godbolt.org:
https://gcc.godbolt.org/z/zSKWsv

---

Similarly, the following code

    template<int = []<typename>(){ return 0; }.operator()<int>()>
    void f() { }

produces another ICE:

    <source>: In member function '<lambda()>::operator decltype
(((const<lambda()>*)((const<lambda()>* const)0))->operator()()) (*)()() const':
    <source>:1:20: internal compiler error: in type_dependent_expression_p, at
cp/pt.c:25602
        1 |     template<int = []<typename>(){ return 0; }.operator()<int>()>
          |    

Live example on godbolt.org:
https://gcc.godbolt.org/z/uOfYy5

Reply via email to