<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/145505>145505</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang] `friend` declaration does not apply during constraint validation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yalavrinenko
      </td>
    </tr>
</table>

<pre>
    I discovered that with the latest `clang-21` the following code stop compiling:
```c++
#include <concepts>

template <typename T>
concept FooType = requires (T *v){
    {v->bar()} -> std::same_as<int>;
};

template <typename T>
struct Bar {
    Bar(T *owner): owner_{owner}{}

    bool func() {
        return owner()->bar() == 10;
    }

    auto owner() requires FooType<T> {
        return owner_;
    }

    T *owner_;
};

class Owner{
    public:
 auto& obj() { return obj_; }

    private:
        friend Bar<Owner>;

 int bar() { return 10; }

        Bar<Owner> obj_{this};
};

int main(){
    Owner o;
    return o.obj().func();
}
```
The compilation error is following:
```
<source>:14:16: error: invalid reference to function 'owner': constraints not satisfied
   14 |         return owner()->bar() == 10;
      |                ^
<source>:38:20: note: in instantiation of member function 'Bar<Owner>::func' requested here
   38 | return o.obj().func();
      |                    ^
<source>:17:27: note: because 'Owner' does not satisfy 'FooType'
   17 |     auto owner() requires FooType<T> {
      |                           ^
<source>:6:9: note: because 'v->bar()' would be invalid: 'bar' is a private member of 'Owner'
 6 |     {v->bar()} -> std::same_as<int>;
```
Link to godbolt: https://godbolt.org/z/PasxrhaEa

Compiler info:
```
> clang --version
Ubuntu clang version 21.0.0 (++20250623082046+1c78d8d9d7bc-1~exp1~20250623082206.2496)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin
```

The code above compiles with `gcc` as well as with `clang-20` and early version of `clang-21`. Unfortunately I can  not provide the last working revision of `clang-21`.

Please clarify whether this behavior is expected?
</pre>
<img width="1" height="1" al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