<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 - Misleading error message when third operand is a reference-to-const to a move-only type."
href="https://bugs.llvm.org/show_bug.cgi?id=41002">41002</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Misleading error message when third operand is a reference-to-const to a move-only type.
</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>Linux
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>eracpp@eml.cc
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Source code:
struct T {
T() = default;
~T() = default;
T(T const&) = delete;
T& operator=(T const&) = delete;
T(T&&) = default;
T& operator=(T&&) = default;
operator bool() const noexcept { return true; }
};
T const& bar() { static T t; return t; }
int main() {
T a;
(void)(a ? static_cast<T&&>(T()) : bar());
return 0;
}
Resulting error message:
<source>:17:17: error: call to deleted constructor of 'const T'
(void)(a ? static_cast<T&&>(T()) : bar());
^~~~~~~~~~~~~~~~~~~~~
<source>:4:3: note: 'T' has been explicitly marked deleted here
T(T const&) = delete;
^
1 error generated.
Compiler returned: 1
The compiler is highlighting the second operand, when the cause of the error is
actually the third operand.
This only seems to occur when all of the following are true:
1 - The "base type" of both operands are the same and are move-only types.
3 - The second operand is an xvalue.
4 - The type of the third operand is a reference to const.
If T is not move-only, this is a valid expression, and there is no error. If
the "base type" (the non-cv-qualifier defining-type-specifier) is not the same,
either an irrelevant error message is produced (e.g. incompatible types), or
the correct expression is highlighted.
If the second operand is a prvalue, the correct expression is highlighted. The
particular type of the expression does not seem to matter so long as the
expression is an xvalue (e.g. `U().t` where `U::t` is a non-static data member
of type `T` produces the same behavior).
If the type of the third operand is not specifically a reference to a const,
the correct expression is highlighted. The kind of reference (lvalue vs.
rvalue) does not seem to matter, so long as the type is a reference to a const.</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>