https://bugs.llvm.org/show_bug.cgi?id=41002
Bug ID: 41002
Summary: Misleading error message when third operand is a
reference-to-const to a move-only type.
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangb...@nondot.org
Reporter: era...@eml.cc
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@metafoo.co.uk
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs