[LLVMbugs] [Bug 23440] New: Implicitly converts lvalue to rvalue when returning reference parameter in function template
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed May 6 23:41:37 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=23440
Bug ID: 23440
Summary: Implicitly converts lvalue to rvalue when returning
reference parameter in function template
Product: clang
Version: 3.5
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: david at doublewise.net
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
#include <type_traits>
template<typename T>
auto compiles(T && t) -> T && {
static_assert(std::is_same<T, int>::value, "Incorrect type deduced for
T.");
return t;
}
static_assert(std::is_same<int &&, decltype(compiles(0))>::value, "shouldn't
compile");
auto fails(int && t) -> int && {
return t;
}
static_assert(std::is_same<int &&, decltype(fails(0))>::value, "doesn't
compile");
Neither function should compile. In the function template case, T is deduced as
int, so the parameter type is int &&. Local variables and function parameters
taken by value can be implicitly moved into the return value, but not function
parameters taken by rvalue reference (t is an lvalue, even though decltype(t)
== int &&).
The non-template function correctly honors this behavior.
If the return type of compiles is changed to decltype(auto) or auto &&, then
the function correctly returns int & and the static_assert fires.
--
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/20150507/70551f2b/attachment.html>
More information about the llvm-bugs
mailing list