<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 - Wrong constraint for std::optional<T>::operator=(U&&)"
href="https://bugs.llvm.org/show_bug.cgi?id=38638">38638</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong constraint for std::optional<T>::operator=(U&&)
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zilla@kayari.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>The following should compile:
#include <optional>
constexpr int foo(int i) {
std::optional<int> o;
o = i;
return *o;
}
Wandbox tells me:
prog.cc:2:15: error: constexpr function never produces a constant expression
[-Winvalid-constexpr]
constexpr int foo(int i) {
^
prog.cc:4:5: note: non-constexpr function 'operator=<int &, void>' cannot be
used in a constant expression
o = i;
^
/opt/wandbox/clang-6.0.0/include/c++/v1/optional:773:5: note: declared here
operator=(_Up&& __v)
^
<a href="https://wandbox.org/permlink/OrXOqTuQHDSddHod">https://wandbox.org/permlink/OrXOqTuQHDSddHod</a>
The note shows that operator=(U&&) is being used, but that should not
participate in overload resolution unless conjunction_v<is_scalar<T>,
is_same<T, decay_t<U>>> is false.
In my code is_scalar<int> is true, and is_same<int, decay_t<int&>> is true.</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>