[llvm-bugs] [Bug 45464] New: Clang rejects private member access used in default template argument of hidden friend

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 7 10:24:38 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45464

            Bug ID: 45464
           Summary: Clang rejects private member access used in default
                    template argument of hidden friend
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lewissbaker at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

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 https://godbolt.org/z/HcqBYn for an example.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200407/9e91a1b9/attachment.html>


More information about the llvm-bugs mailing list