<html>
<head>
<base href="http://llvm.org/bugs/" />
</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 --- - auto in lambda argument fails without warnings"
href="http://llvm.org/bugs/show_bug.cgi?id=22509">22509</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>auto in lambda argument fails without warnings
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.5
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>schnetter@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>In the code below, I create a shared_ptr<double> that is ultimately supposed to
hold the value -1.0, yet the actual value is 1.84467e+19. This looks to me as
if either wrong code is generated, or as if a size_t value is accidentally
interpreted as double.
The code uses "auto" to declare arguments for a lambda expression. If I replace
these "auto" manually by "size_t" -- which are they types that should be
deduced -- the code works fine.
Strangely, the code builds without warnings. If a size_t is accidentally
interpreted as double, I would have expected a warning.
I assume that the deduction of the auto parameters is not working correctly. I
may be wrong about this; in this case, I would expect a warning from the
compiler about mismatching types.
I am using:
$ clang++ --version
clang version 3.5.1 (tags/RELEASE_351/final)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
I build with:
$ clang++ -std=c++14 -g -Wall -o lambda-auto lambda-auto.cc
The code is:
{{{
#include <iostream>
#include <memory>
#include <utility>
template <typename> struct is_shared_ptr : std::false_type {};
template <typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
template <template <typename> class C, typename F, typename... Args,
typename R = std::result_of_t<F(std::size_t, Args...)>,
std::enable_if_t<is_shared_ptr<C<R>>::value> * = nullptr>
auto iota(F &&f, std::size_t s, Args &&... args) {
return std::make_shared<R>(
std::forward<F>(f)(std::size_t(0), std::forward<Args>(args)...));
}
int main(int argc, char **argv) {
auto r = iota<std::shared_ptr>([](auto x, auto y) { return double(x + y); },
std::size_t(1), std::size_t(-1));
static_assert(std::is_same<decltype(r), std::shared_ptr<double>>::value, "");
std::cout << "*r=" << *r << "\n";
return 0;
}
}}}</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>