[LLVMbugs] [Bug 22509] New: auto in lambda argument fails without warnings

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Feb 8 14:15:10 PST 2015


            Bug ID: 22509
           Summary: auto in lambda argument fails without warnings
           Product: new-bugs
           Version: 3.5
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: schnetter at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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;

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/20150208/dbc9e2a6/attachment.html>

More information about the llvm-bugs mailing list