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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2025-11-27
           Keywords|                            |ice-checking
      Known to fail|                            |12.1.0, 12.5.0, 15.1.0
             Status|UNCONFIRMED                 |NEW
            Summary|ICE: in tsubst_expr, at     |[13/14/15/16 Regression]
                   |cp/pt.cc with friend        |ICE: in tsubst_expr, at
                   |default argument of a       |cp/pt.cc with friend
                   |invocation of a lambda from |default argument of a
                   |a templated struct          |invocation of a lambda from
                   |                            |a templated struct
     Ever confirmed|0                           |1
      Known to work|                            |11.4.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
template <typename T>
struct A {
    friend void foo(int i = []() { return 0; }()) {
    }
};
A<int> a;
A<long> c;
```

The error message with release checking is bad too:
```
<source>: In instantiation of 'struct A<long int>':
<source>:9:9:   required from here
    9 | A<long> c;
      |         ^
<source>:4:29: error: taking address of rvalue [-fpermissive]
    4 |     friend void foo(int i = []() { return 0; }()) {
      |                             ^~~~~~~~~~~~~~~~~~
<source>:4:47: error: no matching function for call to
'A<int>::<lambda()>::operator()(A<int>::<lambda()>*)'
    4 |     friend void foo(int i = []() { return 0; }()) {
      |                             ~~~~~~~~~~~~~~~~~~^~
<source>:4:47: note: there is 1 candidate
<source>:4:29: note: candidate 1: 'A<int>::<lambda()>'
    4 |     friend void foo(int i = []() { return 0; }()) {
      |                             ^
<source>:4:29: note: candidate expects 0 arguments, 1 provided
<source>:4:17: note:   when instantiating default argument for call to 'void
foo(int) [with T = long int]'
    4 |     friend void foo(int i = []() { return 0; }()) {
      |                 ^~~
<source>:4:17: error: redefinition of 'void foo(int)'
<source>:4:17: note: 'void foo(int)' previously declared here
Compiler returned: 1
```

In this case only the last error message has an hint of what is going on but
even then it still not obvious.
  • [Bug c++/122833] New: IC... 522024330006 at smail dot nju.edu.cn via Gcc-bugs
    • [Bug c++/122833] [1... pinskia at gcc dot gnu.org via Gcc-bugs

Reply via email to