[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-bugs
Subject:    [llvm-bugs] [Bug 61866] Regression libc++: Usage of std::ref compiles in C++17 but not C++20
From:       LLVM Bugs via llvm-bugs <llvm-bugs () lists ! llvm ! org>
Date:       2023-03-31 11:08:19
Message-ID: 20230331110819.7c896bd78a777746 () email ! llvm ! org
[Download RAW message or body]

[Attachment #2 (text/html)]

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

    <tr>
        <th>Summary</th>
        <td>
            Regression libc++: Usage of std::ref compiles in C++17 but not C++20
        </td>
    </tr>

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

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

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

<pre>
    Tested with Clang 16.0.0.

Minimal example:

```cpp
//#undef __cplusplus
//#define __cplusplus 201703 // compiles when forcing libc++ as if compiling under \
C++17 #include &lt;functional&gt;
#include &lt;iostream&gt;
#include &lt;type_traits&gt;

template&lt;class Fun&gt;
class y_combinator_result {
 Fun fun_;
public:
    template&lt;class T&gt;
    explicit y_combinator_result(T &amp;&amp;fun): fun_(std::forward&lt;T&gt;(fun)) \
{}

 template&lt;class ...Args&gt;
    decltype(auto) operator()(Args &amp;&amp;...args) {
        return fun_(std::ref(*this), std::forward&lt;Args&gt;(args)...);
 }
};

template&lt;class Fun&gt;
decltype(auto) y_combinator(Fun &amp;&amp;fun) {
    return y_combinator_result&lt;std::decay_t&lt;Fun&gt;&gt;(std::forward&lt;Fun&gt;(fun));
 }

int main() 
{
    using Type = int; // Using an other integer type such as &quot;unsigned int&quot; \
makes the code compile  
    auto almost_factorial = [](auto factorial, Type n) -&gt; Type {
        if (n == 0) {
 return static_cast&lt;Type&gt;(1); 
        } else {
            return static_cast&lt;Type&gt;(n * factorial(n-1));
        }
    };
    auto factorial = y_combinator(std::ref(almost_factorial)); // Not using std::ref \
makes the code compile  
    //std::cout &lt;&lt; factorial(5u) &lt;&lt; std::endl; // Uncommenting this line \
makes the code compile  std::cout &lt;&lt; factorial(5) &lt;&lt; std::endl; // Does \
not compile without previous line  
    return 0;
}
```

Compilation output on \
[cpp.sh](https://cpp.sh/?source=%23include+%3Ciostream%3E%0A%23include+%3Ctype_traits% \
3E%0Ausing+namespace+std%3B%0A%0Aint+main()+%0A%7B%0A++++std%3A%3Acout+%3C%3C+083+%3C%3C+std%3A%3Aendl%3B%0A++++%0A++++return+0%3B%0A%7D):


```
main.cpp:33:42: error: no matching function for call to object of type \
&apos;std::reference_wrapper&lt;y_combinator_result&lt;std::reference_wrapper&lt;(lambda \
at main.cpp:29:29)&gt;&gt;&gt;&apos;  return static_cast&lt;Type&gt;(n * \
factorial(n-1));  ^~~~~~~~~
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/type_traits:3640:23: \
note: in instantiation of function template specialization &apos;main()::(anonymous \
class)::operator()&lt;std::reference_wrapper&lt;y_combinator_result&lt;std::reference_wrapper&lt;(lambda \
at main.cpp:29:29)&gt;&gt;&gt;&gt;&apos; requested here  { return \
static_cast&lt;_Fp&amp;&amp;&gt;(__f)(static_cast&lt;_Args&amp;&amp;&gt;(__args)...); \
}  ^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__functional/reference_wrapper.h:60:23: \
note: in instantiation of function template specialization \
&apos;std::__invoke&lt;(lambda at main.cpp:29:29) &amp;, \
std::reference_wrapper&lt;y_combinator_result&lt;std::reference_wrapper&lt;(lambda at \
                main.cpp:29:29)&gt;&gt;&gt;, int&gt;&apos; requested here
        return _VSTD::__invoke(get(), _VSTD::forward&lt;_ArgTypes&gt;(__args)...);
 ^
main.cpp:16:16: note: in instantiation of function template specialization \
&apos;std::reference_wrapper&lt;(lambda at \
main.cpp:29:29)&gt;::operator()&lt;std::reference_wrapper&lt;y_combinator_result&lt;std::reference_wrapper&lt;(lambda \
at main.cpp:29:29)&gt;&gt;&gt;, int&gt;&apos; requested here  return \
fun_(std::ref(*this), std::forward&lt;Args&gt;(args)...);  ^
main.cpp:39:27: note: in instantiation of function template specialization \
&apos;y_combinator_result&lt;std::reference_wrapper&lt;(lambda at \
main.cpp:29:29)&gt;&gt;::operator()&lt;int&gt;&apos; requested here  std::cout \
&lt;&lt; factorial(5) &lt;&lt; std::endl; // Does not compile without previous line  \
                ^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__functional/reference_wrapper.h:59:5: \
note: candidate template ignored: substitution failure [with _ArgTypes = \
&lt;int&gt;]: no type named &apos;type&apos; in \
&apos;std::__invoke_of&lt;y_combinator_result&lt;std::reference_wrapper&lt;(lambda at \
main.cpp:29:29)&gt;&gt; &amp;, int&gt;&apos;  operator() (_ArgTypes&amp;&amp;... \
__args) const {  ^
1 error generated.
```

maybe related to #43743
</pre>
<img width="1px" height="1px" alt="" \
src="http://email.email.llvm.org/o/eJzMWEuT4roV_jVioxqXkcB2L1jwaHZJpW76ZusS8gGUsSVHkru \
HLPLbU0eyjaGZ23Mr0zWhGA8tHZ3Xd16ycE6dNMCKLDdkuZuJzp-NXf1NfYP6NyW_zg6muqxewHmo6JvyZ7qth \
T7ReZakSZqQdEfSdXz-RWnViJrCN9G0NRC-nu6SLI1f2bb9CtuHL-90BUdalrKtO4f_7vYrOCoNUwLK0nmechp \
JqDRNq2pw9O0Mmh6NlUqfaK0OkrANYRsqHFXHngy3UKKl27g7zwd5XGlZdxVQwrfHTkuvjBY14c-PCJRx3oJov \
rPtLy2U3grl3ZUiPD00bS08EL6VtXCO7js9ksSVSylNc1BaeGNLC66rPSX5JpIgPT12uiS8X2m7Q63k6HBKKX0 \
n5GUUgdvwra2VVP6RJMKKF0pYRlh27DRhT4SvozxWOF-hGL4-GvsmbEX4NjBmRU_KnoKi-W5q8XttkiRZ25O70 \
akCWaPXCCtE5w2yMi1Y1IywIjAv8FCvW5IkAln0Ekc2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4mes-z4fH \
zgPof_PZ_l9Z_FsNPuxM9wI4HffOfgd2nevEhqB979RcMi7--cC7Re8sppFLoSlUI24ifOmljAQ2mrjs4r3wXx \
x2h6s4CTqnhXdJYGOJdbXT6ctdPTGESwlGywiCId-ccg-hR3S3N8XPzbajZY2hcY-E2fPDOeC16w-sKOhY-Ko1 \
2_vYCOGI7jzMjPYFGnlAlf3ALaMTlANQCur3CKZIwvuD5gs-qFa-e-JOYwWqeFSnL0uLpaXZeLbMFlwVPD1V6P \
GQLvsjyqsoYy4sq5VIsZ2rFUsZTzufzeVrMn5JcFk_ZocoLked5vsjIIoVGqDqp69cmMfY0U851sMrmRZbNanG \
A2oX3iYxpeKNhkzBGlruZXeGZL4fu5MgirZXz7srFK1_D6jc4WXAOw-X6Bg_D4XcnToD14uZ6Ob77U_r6Qo8eOh-Sql9h6ayz9er2NnRS_twdEmkwZ1CJ_r8vrTU4iWOqoOqOsH0w7b8BAAD__yvgW44">



[Attachment #3 (text/plain)]

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic