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

            Bug ID: 127887
           Summary: [miscompilation] GCC fails to match a friend
                    declaration with its definition when the return type
                    is `C<> auto` with a defaulted concept argument;
                    friendship and access are lost
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 0599jiangyc at gmail dot com
  Target Milestone: ---

The following code:

```cpp
#include <cstdio>
template <typename T, typename = T>
concept C = true;

class K {
  template <class T> static int secret() { return 42; }
  template <class T> friend C<> auto peek(T);
};

template <class T> C<> auto peek(T) {
  if constexpr (requires { K::template secret<T>(); })
    return 1;
  else
    return 2;
}

int main() {
  std::printf("%d\n", peek(0));
  return 0;
}
```

gcc output: 2, https://godbolt.org/z/Ecvh6oja5

expected output: 1, https://godbolt.org/z/zqobv115E

gcc trunk ICE: https://godbolt.org/z/W5rqv67az

Related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119252, but it is only a
crash-on-invalid
  • [Bug c++/127887] New: [miscompil... 0599jiangyc at gmail dot com via Gcc-bugs

Reply via email to