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

    <tr>
        <th>Summary</th>
        <td>
            accessing member in trailing return type of locally defined friend function triggers error with clang
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Example code as below or on [godbolt](https://godbolt.org/z/1Mex1h6zW). All friend functions compile with gcc and Visual Studio. clang fails when trying to access S<T>::foo() in trailing return type. The question could also be found on [stackoverflow](https://stackoverflow.com/a/76544466/5247961).

```
#include <concepts>

template<typename T>
struct S {
    T m_t;

    T const& foo() const& { return m_t; }

    auto mem_fn_trailing_return(S const& s) -> decltype(s.foo()) {
        return s.foo();
    }

    friend auto bar_auto(S const& s) {
        return s.foo();
    }

    friend decltype(auto) bar_decltype_auto(S const& s) {
        return s.foo();
    }

    friend decltype(auto) bar_requires(S const& s) requires std::same_as<T const&, decltype(s.foo())> {
        return s.foo();
    }

    friend auto bar_trailing_return(S const& s) -> decltype(s.foo()) { // clang error: member access into incomplete type 'const S<int>'
        return s.foo();
    }
};

S<int> s{1};
```

According to [expr.ref#4](http://eel.is/c++draft/expr.ref#4):

> Otherwise, the object expression shall be of class type[.](http://eel.is/c++draft/expr.ref#4.sentence-1) The class type shall be complete unless the class member access appears in the definition of that class[.](http://eel.is/c++draft/expr.ref#4.sentence-2)
> [Note [3](http://eel.is/c++draft/expr.ref#note-3): The program is ill-formed if the result differs from that when the class is complete ([[class.member.lookup]](http://eel.is/c++draft/class.member.lookup))[.](http://eel.is/c++draft/expr.ref#4.sentence-3) — end note]
> [Note [4](http://eel.is/c++draft/expr.ref#note-4): [[basic.lookup.qual]](http://eel.is/c++draft/basic.lookup.qual) describes how names are looked up after the . and -> operators[.](http://eel.is/c++draft/expr.ref#4.sentence-4) — end note]

The class member access in trailing return type of a locally defined friend function does appear in the definition of that class. IMO clang should allow it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVs1u4zYQfhr6MohgU_8HH6wkBnrY7iFBewwocmSxS5Faklpv9ukLUoqdpN6mDVLUMCSbnN9vOB-HOScPGnFL8obkNys2-d7Y7ZHpQ8_0mq5aIx63t9_ZMCoEbgQCc9CiMkcwFowGkjcHI1qjPMlvCK1670dH0h2he0L3y1Zi7IHQ_Q9C95tP-H3TFz9-J7ROYKcUdFaiFtBNmntptANuhlEqhKP0PRw4B6YF_CbdxBTc-UlIkwBXTB-gY1I5OPaowdtHqQ_gDTDO0Tm4I-n1PUlvQyzprjOG0IrQGmSQZVIFaYt-shr844gJ3PcIXyd0IQjgZlICmHIGWoTOTFos2TrP-BfzDW2nzPFSzi8EEm4GQveM0H1Z5FmWFQWh-5xmZV1sAgRkfUPWu-VZrJfv_JemUnM1CQSSXnOjOY7ehZSe6XgcRsU8kvQ6pKHZgHB_knHeTtzDHZCymVcAAO5hePAkbZ7bmde50c4TWsAZr9MSKZsnwGZ1IOXNaxNs8gYGHB46_fAE88OsRWh1d7bmgu0rkt6CQK5C6IRWLjn5Ddsvgg6fxf1zsfSZyIV4lsMVw2qZfQg_LgTycZ6eZTP7qqPfp-X_LQCLXydp0V3w_bQFzou5Wxwb8IG50EEnWUKvf16qUMf_oFofcYJg7sqFMdBaY0m6C2e0RftEFlJ7A1IH5lHoMTICEFpGZ5FKpPahq2j5zhzLm1cNdzYKjpTN5oXEKyKIzx3nxoqF5Eje4PfRJhY7QtPszEMnGkJUiXSE7jmhDaGNsKzzYf25Wgh394KC0lv47Hu0R-kwlNz3CKb9A7mHoInOBXp0PVMqMKPpArDORcRI3iTvjCRxqD1qjleBFSMXn-2e3Z0KNGkV6uZPci_rycYRmXWR7HsEgZ3UMhK76cD3zM9aHxIwDSiewCN586vxGN7p-0xr4_EqnUsTgRitOVg2gHQglbrqjB1QgO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