<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang rejects private member access used in default template argument of hidden friend"
   href="https://bugs.llvm.org/show_bug.cgi?id=45464">45464</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang rejects private member access used in default template argument of hidden friend
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lewissbaker@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code is rejected by clang as it complains that referencing a
private data-member in a default template argument decltype() expression is not
allowed.


---
#include <type_traits>
#include <concepts>

template<typename T, typename B>
concept same_base_as = std::same_as<std::remove_cvref_t<T>,
std::remove_cvref_t<B>>;

template<typename T>
struct Y {
    Y(T&&) {}
};

class X {
    int value;

    template<
        same_base_as<X> S,
        typename V = decltype((std::declval<S>().value))>
    friend Y<V> foo(S&& x) {
        return Y<V>{((S&&)x).value};
    }
};

void test() {
    X x;
    auto a = foo(x);
}
---

With the following compile-error:

<source>:42:14: error: no matching function for call to 'foo'
    auto a = foo(x);
             ^~~
<source>:34:17: note: candidate template ignored: substitution failure [with S
= X &, V = int &]: 'value' is a private member of 'X'
    friend Y<V> foo(S&& x) {


Note that if I change the decltype() expression to use `.*&X::value` instead of
`.value` then clang accepts it.

MSVC and GCC both accept the above code, so I suspect it's a bug in Clang.

See <a href="https://godbolt.org/z/HcqBYn">https://godbolt.org/z/HcqBYn</a> for an example.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>